using System.Collections.Generic;
using XEDeviceIdiom = Xamarin.Essentials.DeviceIdiom;
namespace System
{
///
/// 设备种类,例如手机,平板,电视,手表
///
[Flags]
public enum DeviceIdiom
{
///
/// 未知
///
Unknown = 1,
///
/// 手机
///
Phone = 4,
///
/// 平板
///
Tablet = 8,
///
/// 桌面端
///
Desktop = 16,
///
/// 电视
///
TV = 32,
///
/// 手表
///
Watch = 64,
}
///
/// Enum 扩展
///
public static partial class IdiomEnumExtensions
{
///
/// 值是否在定义的范围中,排除
///
///
///
public static bool IsDefined(this DeviceIdiom deviceIdiom)
{
return deviceIdiom != DeviceIdiom.Unknown && Enum.IsDefined(typeof(DeviceIdiom), deviceIdiom);
}
static readonly IReadOnlyDictionary mapping = new Dictionary
{
{ XEDeviceIdiom.Phone, DeviceIdiom.Phone },
{ XEDeviceIdiom.Tablet, DeviceIdiom.Tablet },
{ XEDeviceIdiom.Desktop, DeviceIdiom.Desktop },
{ XEDeviceIdiom.TV, DeviceIdiom.TV },
{ XEDeviceIdiom.Watch, DeviceIdiom.Watch },
};
///
/// 将 转换为
///
///
///
public static DeviceIdiom Convert(this XEDeviceIdiom value) => mapping.ContainsKey(value) ? mapping[value] : DeviceIdiom.Unknown;
}
}