![]() |
От: | Teolog | |
Дата: | 25.04.22 08:20 | ||
Оценка: | 131 (3) |
public static class HackEnumConvert<TEnumType> where TEnumType : struct, Enum
{
private static readonly Func<TEnumType, int> Wrapper;
public static int ToInt(TEnumType enu) {
return Wrapper(enu);
}
static HackEnumConvert() {
var p = Expression.Parameter(typeof(TEnumType), null);
var c = Expression.ConvertChecked(p, typeof(int));
Wrapper = Expression.Lambda<Func<TEnumType, int>>(c, p).Compile();
}
}
HackEnumConvert<EMyEnum>.ToInt(value);