EonaCat.HID/EonaCat.HID/HidFactory.cs

71 lines
1.9 KiB
C#

using System;
using System.Runtime.InteropServices;
namespace EonaCat.HID
{
// This file is part of the EonaCat project(s) which is released under the Apache License.
// See the LICENSE file or go to https://EonaCat.com/license for full license details.
/// <summary>
/// Main static factory class to create platform-specific implementations.
/// </summary>
public static class HidFactory
{
public static string GetPlatform()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return "Windows";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return "macOS";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return "Linux";
}
return "Unknown";
}
public static bool IsWindows()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
}
public static bool IsLinux()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
}
public static bool IsMacOS()
{
return RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
}
public static IHidManager CreateDeviceManager()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return new Managers.Windows.HidManagerWindows();
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return new Managers.Linux.HidManagerLinux();
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return new Managers.Mac.HidManagerMac();
}
else
{
throw new PlatformNotSupportedException("Unsupported platform");
}
}
}
}