using WCS.Core; namespace WCS.WorkEngineering.Extensions { /// /// 设备标签扩展 /// public static class DeviceFlagExtension { /// /// 获取指定设备标签的值 /// /// /// /// /// public static T GetFlag(this Device device, string key) { if (!device.HasFlag(key)) { if (typeof(T) == typeof(int)) device.AddFlag(key, default(int).ToString()); else if (typeof(T) == typeof(short)) device.AddFlag(key, default(bool).ToString()); else if (typeof(T) == typeof(bool)) device.AddFlag(key, default(bool).ToString()); } var valeu = device.GetFlags(key).FirstOrDefault(); return (T)Convert.ChangeType(valeu, typeof(T)); } /// /// 设置指定设备标签的值 /// /// /// /// /// /// public static void SetFlag(this Device device, string key, T value) { device.SetFlag(key, value.ToString()); } } }