static readonly Dictionary<string, DeviceType> MappedDeviceType;
static fnMapDeviceType()
{
MappedDeviceType = new Dictionary<string, DeviceType>();
MappedDeviceType.Add("Windows NT 6.3", DeviceType.Windows);
MappedDeviceType.Add("Windows NT 6.3; WOW64", DeviceType.Windows);
MappedDeviceType.Add("Windows NT 10.0", DeviceType.Windows);
MappedDeviceType.Add("Windows NT 10.0; WOW64", DeviceType.Windows);
MappedDeviceType.Add("CPU iPhone OS 9_3_2 like Mac OS X", DeviceType.Iphone);
}
public static DeviceType MapDeviceType(string device)
{
DeviceType mapValue = DeviceType.Unknown;
if (!string.IsNullOrWhiteSpace(device))
{
if (Enum.TryParse(device, true, out mapValue))
return mapValue;
if (MappedDeviceType.TryGetValue(device,
out mapValue))
return mapValue;
}
return mapValue;
}
---------------------
//Contain en with key
---------------------
//Contain en with key
string word = "en/my";
var mappingA = new Dictionary<string, string>()
{
{ "en", "en-gb" },
{ "cn", "cn-zh" },
};
string listPerson = mappingA.Where(x =>
word.Contains(x.Key)).Select(y => y.Value).FirstOrDefault();
No comments:
Post a Comment