10 static bool HasFlag(
int flags,
int condition)
12 return (flags & condition) == condition;
22 static bool HasPartialFlag(
int flags,
int condition)
24 return (condition & ~flags) != condition;
34 static int SetFlag(
int flags,
int flagToSet)
47 static int RemoveFlag(
int flags,
int flagToRemove)
49 flags &= ~flagToRemove;
58 static int BitToIntArray(
int bitValue, out notnull array<int> intValues)
63 while (i > 0 && i <
int.MAX)
79 static int IntToBitArray(notnull array<int> intValues)
82 foreach (
int intValue: intValues)
96 static string GetEnumName(
typename enumType,
int enumValue)
98 return typename.EnumToString(enumType, enumValue);
108 static int GetEnumNames(
typename enumType, out notnull array<string> stringValues)
110 stringValues.Clear();
111 array<int> values = {};
112 GetEnumValues(enumType, values);
113 for (
int i, count = values.Count(); i < count; i++)
115 stringValues.Insert(
typename.EnumToString(enumType, values[i]));
117 return stringValues.Count();
127 static int GetEnumValues(
typename enumType, out notnull array<int> intValues)
130 for (
int i, count = enumType.GetVariableCount(); i < count; i++)
132 if (enumType.GetVariableValue(
null, i, val))
133 intValues.Insert(val);
135 return intValues.Count();
144 static int GetFlagValues(
typename enumType)
147 for (
int i, count = enumType.GetVariableCount(); i < count; i++)
149 if (enumType.GetVariableValue(
null, i, val))
163 static bool GetRange(
typename enumType, out
int min, out
int max)
167 int val, count = enumType.GetVariableCount();
168 for (
int i = 0; i < count; i++)
170 if (enumType.GetVariableValue(
null, i, val))
172 min = Math.Min(min, val);
173 max = Math.Max(max, val);
188 static ParamEnumArray GetList(
typename e, ParamEnum customValue1 =
null, ParamEnum customValue2 =
null, ParamEnum customValue3 =
null)
190 ParamEnumArray
params = ParamEnumArray.FromEnum(e);
193 params.InsertAt(customValue3, 0);
195 params.InsertAt(customValue2, 0);
197 params.InsertAt(customValue1, 0);
208 static ParamEnumArray GetList(notnull array<string> names)
210 ParamEnumArray
params = {};
211 for (
int i, count = names.Count(); i < count; i++)
213 params.Insert(
new ParamEnum(names[i], i.ToString()));
224 static ParamEnumArray GetFlags(notnull array<string> names)
226 ParamEnumArray
params = {};
227 for (
int i, count = names.Count(); i < count; i++)
229 params.Insert(
new ParamEnum(names[i], Math.Pow(2, i).ToString()));
243 static string FlagsToString(
typename e,
int flags,
string delimiter =
", ",
string noValue =
"N/A")
248 array<int> outValues = {};
250 int count = BitToIntArray(flags, outValues);
254 string result =
typename.EnumToString(e, outValues[0]);
255 for (
int i = 1; i < count; i++)
258 result +=
typename.EnumToString(e, outValues[i]);
269 static string GetDefault(
int enumValue)
271 return string.Format(
"%1", enumValue);
280 static string GetDefault(
typename enumType)
282 return GetDefault(GetFlagValues(enumType));