using System.Collections.Generic;
using Xamarin.Essentials;
namespace System
{
///
/// 平台
///
[Flags]
public enum Platform
{
///
/// 未知
///
Unknown = 1,
///
/// Microsoft Windows / UWP(Universal Windows Platform)
///
Windows = 4,
///
/// Ubuntu / Debian / CentOS / Tizen
///
Linux = 8,
///
/// Android Phone / Android Pad / WearOS(Android Wear) / Android TV
///
Android = 16,
///
/// iOS / iPadOS / watchOS / tvOS / macOS
///
Apple = 32,
}
///
/// Enum 扩展
///
public static partial class PlatformEnumExtensions
{
///
/// 值是否在定义的范围中,排除
///
///
///
public static bool IsDefined(this Platform platform)
{
return platform != Platform.Unknown && Enum.IsDefined(typeof(Platform), platform);
}
static readonly IReadOnlyDictionary mapping = new Dictionary
{
{ DevicePlatform.Android, Platform.Android },
{ DevicePlatform.iOS, Platform.Apple },
{ DevicePlatform.UWP, Platform.Windows },
{ DevicePlatform.tvOS, Platform.Apple },
{ DevicePlatform.Tizen, Platform.Linux },
{ DevicePlatform.watchOS, Platform.Apple },
};
///
/// 将 转换为
///
///
///
public static Platform Convert(this DevicePlatform value) => mapping.ContainsKey(value) ? mapping[value] : Platform.Unknown;
}
}