Changeset 15009
- Timestamp:
- 05/31/17 13:29:27 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Data.Views/3.3/EnumValueView.cs
r14597 r15009 43 43 } 44 44 45 static EnumValueView() { 46 if (!typeof(T).IsEnum) 47 throw new InvalidOperationException("Generic type " + typeof(T).Name + " is not an enum."); 48 } 49 45 50 public EnumValueView() { 46 51 InitializeComponent(); 47 this. Name= typeof(T).Name + "EnumView";52 this.Caption = typeof(T).Name + "EnumView"; 48 53 49 54 valueComboBox.DataSource = Enum.GetValues(typeof(T)); … … 121 126 } 122 127 } 128 129 internal static class EnumHelper { 130 //https://stackoverflow.com/a/21581418 131 public static T SetFlag<T>(this Enum value, T flag, bool set) { 132 var baseType = Enum.GetUnderlyingType(value.GetType()); 133 dynamic valueAsBase = Convert.ChangeType(value, baseType); 134 dynamic flagAsBase = Convert.ChangeType(flag, baseType); 135 if (set) 136 valueAsBase |= flagAsBase; 137 else 138 valueAsBase &= ~flagAsBase; 139 return (T)valueAsBase; 140 } 141 } 123 142 } -
trunk/sources/HeuristicLab.Data.Views/3.3/HeuristicLab.Data.Views-3.3.csproj
r13425 r15009 105 105 </PropertyGroup> 106 106 <ItemGroup> 107 <Reference Include="Microsoft.CSharp" /> 107 108 <Reference Include="System" /> 108 109 <Reference Include="System.Core"> -
trunk/sources/HeuristicLab.Data/3.3/EnumValue.cs
r14597 r15009 62 62 } 63 63 } 64 65 public static class EnumHelper {66 public static T SetFlag<T>(this Enum value, T flag, bool set) {67 var baseType = Enum.GetUnderlyingType(value.GetType());68 dynamic valueAsBase = Convert.ChangeType(value, baseType);69 dynamic flagAsBase = Convert.ChangeType(flag, baseType);70 if (set)71 valueAsBase |= flagAsBase;72 else73 valueAsBase &= ~flagAsBase;74 return (T)valueAsBase;75 }76 }77 64 } -
trunk/sources/HeuristicLab.Data/3.3/HeuristicLab.Data-3.3.csproj
r14597 r15009 108 108 </PropertyGroup> 109 109 <ItemGroup> 110 <Reference Include="Microsoft.CSharp" />111 110 <Reference Include="System" /> 112 111 <Reference Include="System.Core">
Note: See TracChangeset
for help on using the changeset viewer.