using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Reflection;
namespace System
{
/// <summary>
/// 注意任何enum方法调用将有可能消耗内存字节=sum(枚举值名称字符个数)*2+sum(枚举值个数)*4
/// 因为,任何使用enum方法的行为都会增加System.Enum type object内部的哈希表的对enum object的names和values的缓存(已经在缓存的枚举类型不再缓存),缓存上限是101;
/// 达到上限后再调用新的enum将导致缓存的清空,然后必须对所有的之前的缓存在未来的调用中重新进行缓存。
/// 根据BCL的enum统计,缓存上限可达到30-50M,这个不是一个小数目,所以要小心大量不同枚举的同时使用。
/// </summary>
[Serializable,ComVisible(true)]
public abstract class Enum:System.ValueType,System.IComparable,System.IFormattable,System.IConvertible
{
private class HashEntry:System.Object
{
public string[] names;
public ulong[] values;
public HashEntry(string[] names, ulong[] values):base()
{
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance void System.Object::.ctor()
//IL_0006: ldarg.0
//IL_0007: ldarg.1
//IL_0008: stfld string[] System.Enum/HashEntry::names
//IL_000d: ldarg.0
//IL_000e: ldarg.2
//IL_000f: stfld uint64[] System.Enum/HashEntry::values
//IL_0014: ret
this.names = names;
this.values = values;
}
}
private const string enumSeperator = ", ";
private const int maxHashElements = (int)(0x00000064);
private static char[] enumSeperatorCharArray;
private static System.Type intType;
private static System.Type stringType;
private static System.Collections.Hashtable fieldInfoHash;
private static System.Reflection.FieldInfo GetValueField( System.Type @type)
{
//.maxstack 2
//.locals init (class System.Reflection.FieldInfo[] V_0)
//IL_0000: ldarg.0
//IL_0001: ldc.i4.s 52
//IL_0003: callvirt instance class System.Reflection.FieldInfo[] System.Type::GetFields(valuetype System.Reflection.BindingFlags)
//IL_0008: stloc.0
//IL_0009: ldloc.0
//IL_000a: brfalse.s IL_0012
//IL_000c: ldloc.0
//IL_000d: ldlen
//IL_000e: conv.i4
//IL_000f: ldc.i4.1
//IL_0010: beq.s IL_0022
//IL_0012: ldstr "Arg_EnumMustHaveUnderlyingValueField"
//IL_0017: call string System.Environment::GetResourceString(string)
//IL_001c: newobj instance void System.ArgumentException::.ctor(string)
//IL_0021: throw
//IL_0022: ldloc.0
//IL_0023: ldc.i4.0
//IL_0024: ldelem.ref
//IL_0025: ret
FieldInfo[] V_0;
V_0 = @type.GetFields(BindingFlags.Instance|BindingFlags.Public|BindingFlags.NonPublic);
if (V_0 != null&&V_0.Length==1)
{
return V_0[0];
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_EnumMustHaveUnderlyingValueField"));
}
}
/// <summary>
/// 实际是获取缓存在System.Enum Type Type Object的私有字段fieldInfoHash(哈希表)中的标识特定自定义enum的System.Enum.HashEntry(包含enum类型的names和values集合)
/// 如果已经缓存在哈希表中(哈希表最大缓存量设置为101),则直接返回。
/// 如果没有缓存在哈希表中:
/// 0.如果哈希表缓存项超过100,则清空所有缓存项。
/// 1.父类型为System.Enum,直接利用System.Enum.InternalGetEnumValues()获取names和values集合,并构建System.Enum.HashEntry,并缓存在fieldInfoHash
/// 2.父类型不是System.Enum(估计可能是从其子类继承,csharp不支持),获取该类型的所有public static的字段,
/// 将字段名称放入names中,System.Enum.ToUInt64()将字段值转换成ulong存入values中;将values按照从小到大排序,names对应values顺序排列。
/// 排序方法是假定前n-1个已经是顺序列,前n-1个逆序与第n个比较,如果大于n就做到自己的后一个位置;如果小于n,n便坐在其后。
/// </summary>
/// <param name="enumType"></param>
/// <returns></returns>
private static System.Enum.HashEntry GetHashEntry( System.Type enumType)
{
#region IL
//.maxstack 5
//.locals init (class System.Enum/HashEntry V_0,
//uint64[] V_1,
//string[] V_2,
//class System.Reflection.FieldInfo[] V_3,
//int32 V_4,
//int32 V_5,
//int32 V_6,
//string V_7,
//uint64 V_8,
//bool V_9)
//IL_0000: ldsfld class System.Collections.Hashtable System.Enum::fieldInfoHash
//IL_0005: ldarg.0
//IL_0006: callvirt instance object System.Collections.Hashtable::get_Item(object)
//IL_000b: castclass System.Enum/HashEntry
//IL_0010: stloc.0
//IL_0011: ldloc.0
//IL_0012: brtrue IL_0117
//IL_0017: ldsfld class System.Collections.Hashtable System.Enum::fieldInfoHash
//IL_001c: callvirt instance int32 System.Collections.Hashtable::get_Count()
//IL_0021: ldc.i4.s 100
//IL_0023: ble.s IL_002f
//IL_0025: ldsfld class System.Collections.Hashtable System.Enum::fieldInfoHash
//IL_002a: callvirt instance void System.Collections.Hashtable::Clear()
//IL_002f: ldnull
//IL_0030: stloc.1
//IL_0031: ldnull
//IL_0032: stloc.2
//IL_0033: ldarg.0
//IL_0034: callvirt instance class System.Type System.Type::get_BaseType()
//IL_0039: ldtoken System.Enum
//IL_003e: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0043: bne.un.s IL_0054
//IL_0045: ldarg.0
//IL_0046: ldloca.s V_1
//IL_0048: ldloca.s V_2
//IL_004a: call void System.Enum::InternalGetEnumValues(class System.Type,
//uint64[]&,
//string[]&)
//IL_004f: br IL_0103
//IL_0054: ldarg.0
//IL_0055: ldc.i4.s 24
//IL_0057: callvirt instance class System.Reflection.FieldInfo[] System.Type::GetFields(valuetype System.Reflection.BindingFlags)
//IL_005c: stloc.3
//IL_005d: ldloc.3
//IL_005e: ldlen
//IL_005f: conv.i4
//IL_0060: newarr System.UInt64
//IL_0065: stloc.1
//IL_0066: ldloc.3
//IL_0067: ldlen
//IL_0068: conv.i4
//IL_0069: newarr System.String
//IL_006e: stloc.2
//IL_006f: ldc.i4.0
//IL_0070: stloc.s V_4
//IL_0072: br.s IL_009a
//IL_0074: ldloc.2
//IL_0075: ldloc.s V_4
//IL_0077: ldloc.3
//IL_0078: ldloc.s V_4
//IL_007a: ldelem.ref
//IL_007b: callvirt instance string System.Reflection.MemberInfo::get_Name()
//IL_0080: stelem.ref
//IL_0081: ldloc.1
//IL_0082: ldloc.s V_4
//IL_0084: ldloc.3
//IL_0085: ldloc.s V_4
//IL_0087: ldelem.ref
//IL_0088: ldnull
//IL_0089: callvirt instance object System.Reflection.FieldInfo::GetValue(object)
//IL_008e: call uint64 System.Enum::ToUInt64(object)
//IL_0093: stelem.i8
//IL_0094: ldloc.s V_4
//IL_0096: ldc.i4.1
//IL_0097: add
//IL_0098: stloc.s V_4
//IL_009a: ldloc.s V_4
//IL_009c: ldloc.3
//IL_009d: ldlen
//IL_009e: conv.i4
//IL_009f: blt.s IL_0074
//IL_00a1: ldc.i4.1
//IL_00a2: stloc.s V_5
//IL_00a4: br.s IL_00fc
//IL_00a6: ldloc.s V_5
//IL_00a8: stloc.s V_6
//IL_00aa: ldloc.2
//IL_00ab: ldloc.s V_5
//IL_00ad: ldelem.ref
//IL_00ae: stloc.s V_7
//IL_00b0: ldloc.1
//IL_00b1: ldloc.s V_5
//IL_00b3: ldelem.i8
//IL_00b4: stloc.s V_8
//IL_00b6: ldc.i4.0
//IL_00b7: stloc.s V_9
//IL_00b9: br.s IL_00dc
//IL_00bb: ldloc.2
//IL_00bc: ldloc.s V_6
//IL_00be: ldloc.2
//IL_00bf: ldloc.s V_6
//IL_00c1: ldc.i4.1
//IL_00c2: sub
//IL_00c3: ldelem.ref
//IL_00c4: stelem.ref
//IL_00c5: ldloc.1
//IL_00c6: ldloc.s V_6
//IL_00c8: ldloc.1
//IL_00c9: ldloc.s V_6
//IL_00cb: ldc.i4.1
//IL_00cc: sub
//IL_00cd: ldelem.i8
//IL_00ce: stelem.i8
//IL_00cf: ldloc.s V_6
//IL_00d1: ldc.i4.1
//IL_00d2: sub
//IL_00d3: stloc.s V_6
//IL_00d5: ldc.i4.1
//IL_00d6: stloc.s V_9
//IL_00d8: ldloc.s V_6
//IL_00da: brfalse.s IL_00e6
//IL_00dc: ldloc.1
//IL_00dd: ldloc.s V_6
//IL_00df: ldc.i4.1
//IL_00e0: sub
//IL_00e1: ldelem.i8
//IL_00e2: ldloc.s V_8
//IL_00e4: bgt.un.s IL_00bb
//IL_00e6: ldloc.s V_9
//IL_00e8: brfalse.s IL_00f6
//IL_00ea: ldloc.2
//IL_00eb: ldloc.s V_6
//IL_00ed: ldloc.s V_7
//IL_00ef: stelem.ref
//IL_00f0: ldloc.1
//IL_00f1: ldloc.s V_6
//IL_00f3: ldloc.s V_8
//IL_00f5: stelem.i8
//IL_00f6: ldloc.s V_5
//IL_00f8: ldc.i4.1
//IL_00f9: add
//IL_00fa: stloc.s V_5
//IL_00fc: ldloc.s V_5
//IL_00fe: ldloc.1
//IL_00ff: ldlen
//IL_0100: conv.i4
//IL_0101: blt.s IL_00a6
//IL_0103: ldloc.2
//IL_0104: ldloc.1
//IL_0105: newobj instance void System.Enum/HashEntry::.ctor(string[],
//uint64[])
//IL_010a: stloc.0
//IL_010b: ldsfld class System.Collections.Hashtable System.Enum::fieldInfoHash
//IL_0110: ldarg.0
//IL_0111: ldloc.0
//IL_0112: callvirt instance void System.Collections.Hashtable::set_Item(object,
//object)
//IL_0117: ldloc.0
//IL_0118: ret
#endregion
System.Enum.HashEntry V_0;
ulong[] V_1;
string[] V_2;
FieldInfo[] V_3;
int V_4, V_5, V_6;
string V_7;
ulong V_8;
bool V_9;
V_0=(System.Enum.HashEntry)System.Enum.fieldInfoHash[enumType];
if(V_0==null)
{
if(System.Enum.fieldInfoHash.Count>100)
{
System.Enum.fieldInfoHash.Clear();
}
//IL_002f
V_1=null;
V_2=null;
if(enumType.BaseType==typeof(System.Enum))
{
System.Enum.InternalGetEnumValues(enumType,ref V_1,ref V_2);
//直接跳往IL_0103
V_0 = new System.Enum.HashEntry(V_2, V_1);
System.Enum.fieldInfoHash[enumType] = V_0;
return V_0;
}
else
{
//IL_0054
V_3 = enumType.GetFields(BindingFlags.Public|BindingFlags.Static);
V_1 = new ulong[V_3.Length];
V_2 = new string[V_3.Length];
V_4 = 0;
//IL_0072
//直接跳往IL_009a
while(V_4<V_3.Length)
{
//跳往IL_0074
V_2[V_4] = V_3[V_4].Name;
V_1[V_4] = System.Enum.ToUInt64(V_3[V_4].GetValue(null));
V_4 += 1;
//IL_009a
}
//IL_00a1
V_5=1;
//直接跳往IL_00fc
while(V_5<V_1.Length)//满足跳往IL_00a6
{
//IL_00a6
V_6 = V_5;
V_7 = V_2[V_5];
V_8 = V_1[V_5];
V_9 = 0;
//直接跳往IL_00dc
while (V_1[V_6 - 1] > V_8)//满足条件跳往IL_00bb,不满足跳往IL_00e6
{
//IL_00bb
V_2[V_6]=V_2[V_6-1];
V_1[V_6]=V_1[V_6-1];
V_6=V_6-1;
V_9=1;
if(V_6==0)
{
//IL_00e6
break;
}
else
{
//IL_00dc
continue;
}
}
//IL_00e6
if(V_9==0)
{
//IL_00f6
V_5 = V_5 + 1;
//IL_00fc
}
else
{
V_2[V_6]=V_7;
V_1[V_6]=V_8;
V_5=V_5+1;
//IL_00fc
}
//IL_00fc
continue;
}
//IL_0103
V_0 = new System.Enum.HashEntry(V_2, V_1);
System.Enum.fieldInfoHash[enumType] = V_0;
return V_0;
}
}
else
{
//IL_0117
return V_0;
}
}
/// <summary>
/// 利用System.Enum.GetHashEntry()获取保存其类型相关的values和names集合
/// 利用System.Enum.GetUnderlyingType()获取其底层类型是否是允许的整型。
/// 利用System.Enum.ToUInt64()获取ulong,并在values数组中进行半分查找,如果找到返回对应的names数组中的字符串。
/// 其他情况返回null。
/// </summary>
/// <param name="enumType"></param>
/// <param name="value"></param>
/// <returns></returns>
private static string InternalGetValueAsString( System.Type enumType, object @value)
{
//.maxstack 2
//.locals init (class System.Enum/HashEntry V_0,
//class System.Type V_1,
//uint64 V_2,
//int32 V_3)
//IL_0000: ldarg.0
//IL_0001: call class System.Enum/HashEntry System.Enum::GetHashEntry(class System.Type)
//IL_0006: stloc.0
//IL_0007: ldarg.0
//IL_0008: call class System.Type System.Enum::GetUnderlyingType(class System.Type)
//IL_000d: stloc.1
//IL_000e: ldloc.1
//IL_000f: ldsfld class System.Type System.Enum::intType
//IL_0014: beq.s IL_0071
//IL_0016: ldloc.1
//IL_0017: ldtoken System.Int16
//IL_001c: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0021: beq.s IL_0071
//IL_0023: ldloc.1
//IL_0024: ldtoken System.Int64
//IL_0029: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_002e: beq.s IL_0071
//IL_0030: ldloc.1
//IL_0031: ldtoken System.UInt16
//IL_0036: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_003b: beq.s IL_0071
//IL_003d: ldloc.1
//IL_003e: ldtoken System.Byte
//IL_0043: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0048: beq.s IL_0071
//IL_004a: ldloc.1
//IL_004b: ldtoken System.SByte
//IL_0050: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0055: beq.s IL_0071
//IL_0057: ldloc.1
//IL_0058: ldtoken System.UInt32
//IL_005d: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0062: beq.s IL_0071
//IL_0064: ldloc.1
//IL_0065: ldtoken System.UInt64
//IL_006a: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_006f: bne.un.s IL_0092
//IL_0071: ldarg.1
//IL_0072: call uint64 System.Enum::ToUInt64(object)
//IL_0077: stloc.2
//IL_0078: ldloc.0
//IL_0079: ldfld uint64[] System.Enum/HashEntry::values
//IL_007e: ldloc.2
//IL_007f: call int32 System.Enum::BinarySearch(uint64[],
//uint64)
//IL_0084: stloc.3
//IL_0085: ldloc.3
//IL_0086: ldc.i4.0
//IL_0087: blt.s IL_0092
//IL_0089: ldloc.0
//IL_008a: ldfld string[] System.Enum/HashEntry::names
//IL_008f: ldloc.3
//IL_0090: ldelem.ref
//IL_0091: ret
//IL_0092: ldnull
//IL_0093: ret
System.Enum.HashEntry V_0;
System.Type V_1;
ulong V_2;
int V_3;
V_0 = System.Enum.GetHashEntry(enumType);
V_1 = System.Enum.GetUnderlyingType(enumType);
if (V_1 == System.Enum.intType || V_1 == typeof(short) || V_1 == typeof(long) || V_1 == typeof(ushort) || V_1 == typeof(byte) || V_1 == typeof(sbyte) || V_1 == typeof(uint) || V_1 == typeof(ulong))
{
V_2 = System.Enum.ToUInt64(@value);
V_3=System.Enum.BinarySearch(V_0.values, V_2);
if (V_3 < 0)
{
return null;
}
return V_0.names[V_3];
}
else
{
return null;
}
}
private static string InternalFormattedHexString(object @value)
{
//.maxstack 3
//.locals init (valuetype System.TypeCode V_0,
//uint8 V_1,
//uint8 V_2,
//uint16 V_3,
//uint16 V_4,
//uint32 V_5,
//uint32 V_6,
//uint64 V_7,
//uint64 V_8,
//valuetype System.TypeCode V_9)
//IL_0000: ldarg.0
//IL_0001: call valuetype System.TypeCode System.Convert::GetTypeCode(object)
//IL_0006: stloc.0
//IL_0007: ldloc.0
//IL_0008: stloc.s V_9
//IL_000a: ldloc.s V_9
//IL_000c: ldc.i4.5
//IL_000d: sub
//IL_000e: switch (
//IL_0038,
//IL_004e,
//IL_0063,
//IL_0079,
//IL_00a5,
//IL_008f,
//IL_00d1,
//IL_00bb)
//IL_0033: br IL_00e7
//IL_0038: ldarg.0
//IL_0039: unbox.any System.SByte
//IL_003e: conv.u1
//IL_003f: stloc.1
//IL_0040: ldloca.s V_1
//IL_0042: ldstr "X2"
//IL_0047: ldnull
//IL_0048: call instance string System.Byte::ToString(string,
//class System.IFormatProvider)
//IL_004d: ret
//IL_004e: ldarg.0
//IL_004f: unbox.any System.Byte
//IL_0054: stloc.2
//IL_0055: ldloca.s V_2
//IL_0057: ldstr "X2"
//IL_005c: ldnull
//IL_005d: call instance string System.Byte::ToString(string,
//class System.IFormatProvider)
//IL_0062: ret
//IL_0063: ldarg.0
//IL_0064: unbox.any System.Int16
//IL_0069: conv.u2
//IL_006a: stloc.3
//IL_006b: ldloca.s V_3
//IL_006d: ldstr "X4"
//IL_0072: ldnull
//IL_0073: call instance string System.UInt16::ToString(string,
//class System.IFormatProvider)
//IL_0078: ret
//IL_0079: ldarg.0
//IL_007a: unbox.any System.UInt16
//IL_007f: stloc.s V_4
//IL_0081: ldloca.s V_4
//IL_0083: ldstr "X4"
//IL_0088: ldnull
//IL_0089: call instance string System.UInt16::ToString(string,
//class System.IFormatProvider)
//IL_008e: ret
//IL_008f: ldarg.0
//IL_0090: unbox.any System.UInt32
//IL_0095: stloc.s V_5
//IL_0097: ldloca.s V_5
//IL_0099: ldstr "X8"
//IL_009e: ldnull
//IL_009f: call instance string System.UInt32::ToString(string,
//class System.IFormatProvider)
//IL_00a4: ret
//IL_00a5: ldarg.0
//IL_00a6: unbox.any System.Int32
//IL_00ab: stloc.s V_6
//IL_00ad: ldloca.s V_6
//IL_00af: ldstr "X8"
//IL_00b4: ldnull
//IL_00b5: call instance string System.UInt32::ToString(string,
//class System.IFormatProvider)
//IL_00ba: ret
//IL_00bb: ldarg.0
//IL_00bc: unbox.any System.UInt64
//IL_00c1: stloc.s V_7
//IL_00c3: ldloca.s V_7
//IL_00c5: ldstr "X16"
//IL_00ca: ldnull
//IL_00cb: call instance string System.UInt64::ToString(string,
//class System.IFormatProvider)
//IL_00d0: ret
//IL_00d1: ldarg.0
//IL_00d2: unbox.any System.Int64
//IL_00d7: stloc.s V_8
//IL_00d9: ldloca.s V_8
//IL_00db: ldstr "X16"
//IL_00e0: ldnull
//IL_00e1: call instance string System.UInt64::ToString(string,
//class System.IFormatProvider)
//IL_00e6: ret
//IL_00e7: ldstr "InvalidOperation_UnknownEnumType"
//IL_00ec: call string System.Environment::GetResourceString(string)
//IL_00f1: newobj instance void System.InvalidOperationException::.ctor(string)
//IL_00f6: throw
System.TypeCode V_0;
byte V_1, V_2;
ushort V_3, V_4;
uint V_5, V_6;
ulong V_7, V_8;
System.TypeCode V_9;
V_0=System.Convert.GetTypeCode(@value);
V_9=V_0;
switch(V_9)
{
case TypeCode.SByte:
{
V_1 = (byte)@value;
return V_1.ToString("X2",null);
}
case TypeCode.Byte:
{
V_2 = (byte)@value;
return V_2.ToString("X2", null);
}
case TypeCode.Int16:
{
V_3 = (ushort)@value;
return V_3.ToString("X4", null);
}
case TypeCode.UInt16:
{
V_4 = (ushort)@value;
return V_4.ToString("X4", null);
}
case TypeCode.Int32:
{
V_5 = (uint)@value;
return V_5.ToString("X8", null);
}
case TypeCode.UInt32:
{
V_6 = (uint)@value;
return V_6.ToString("X8", null);
}
case TypeCode.Int64:
{
V_7 = (ulong)@value;
return V_7.ToString("X16", null);
}
case TypeCode.UInt64:
{
V_8 = (ulong)@value;
return V_8.ToString("X16", null);
}
default:
throw new System.InvalidOperationException(System.Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
}
}
private static string InternalFormat( System.Type eT, object @value)
{
//.maxstack 3
//.locals init (string V_0)
//IL_0000: ldarg.0
//IL_0001: ldtoken System.FlagsAttribute
//IL_0006: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_000b: ldc.i4.0
//IL_000c: callvirt instance bool System.Reflection.MemberInfo::IsDefined(class System.Type,
//bool)
//IL_0011: brtrue.s IL_0027
//IL_0013: ldarg.0
//IL_0014: ldarg.1
//IL_0015: call string System.Enum::InternalGetValueAsString(class System.Type,
//object)
//IL_001a: stloc.0
//IL_001b: ldloc.0
//IL_001c: brtrue.s IL_0025
//IL_001e: ldarg.1
//IL_001f: callvirt instance string System.Object::ToString()
//IL_0024: ret
//IL_0025: ldloc.0
//IL_0026: ret
//IL_0027: ldarg.0
//IL_0028: ldarg.1
//IL_0029: call string System.Enum::InternalFlagsFormat(class System.Type,
//object)
//IL_002e: ret
string V_0;
if (eT.IsDefined(typeof(System.FlagsAttribute), false))
{
return System.Enum.InternalFlagsFormat(eT, @value);
}
else
{
V_0 = System.Enum.InternalGetValueAsString(eT,@value);
if (V_0 == null)
{
return @value.ToString();
}
else
{
return V_0;
}
}
}
/// <summary>
/// 获取FlagsAttribute的字符串表示。
/// FlagsAttribute标识的enum类型必须遵守如下规则:枚举值必须>=0,正常来说枚举值占据各异的一个二进制位,也可以定义一个枚举是其它枚举的或集。
/// 如果待翻译的值大于0,则从最大值开始进行and比较,并从待翻译值中减去为真者,继续比较下一个。但是不与0值比较,如果最后待翻译能够被消减为0,则逆向用", "连接所有字符串并返回,否则直接返回待翻译的数值字符串。
/// 如果待翻译的值为0,如果枚举集合中也存在0值,则直接返回对应的名称,否者返回"0"
/// </summary>
/// <param name="eT"></param>
/// <param name="value"></param>
/// <returns></returns>
private static string InternalFlagsFormat( System.Type eT, object @value)
{
//.maxstack 4
//.locals init (uint64 V_0,
//class System.Enum/HashEntry V_1,
//string[] V_2,
//uint64[] V_3,
//int32 V_4,
//class System.Text.StringBuilder V_5,
//bool V_6,
//uint64 V_7)
//IL_0000: ldarg.1
//IL_0001: call uint64 System.Enum::ToUInt64(object)
//IL_0006: stloc.0
//IL_0007: ldarg.0
//IL_0008: call class System.Enum/HashEntry System.Enum::GetHashEntry(class System.Type)
//IL_000d: stloc.1
//IL_000e: ldloc.1
//IL_000f: ldfld string[] System.Enum/HashEntry::names
//IL_0014: stloc.2
//IL_0015: ldloc.1
//IL_0016: ldfld uint64[] System.Enum/HashEntry::values
//IL_001b: stloc.3
//IL_001c: ldloc.3
//IL_001d: ldlen
//IL_001e: conv.i4
//IL_001f: ldc.i4.1
//IL_0020: sub
//IL_0021: stloc.s V_4
//IL_0023: newobj instance void System.Text.StringBuilder::.ctor()
//IL_0028: stloc.s V_5
//IL_002a: ldc.i4.1
//IL_002b: stloc.s V_6
//IL_002d: ldloc.0
//IL_002e: stloc.s V_7
//IL_0030: br.s IL_0079
//IL_0032: ldloc.s V_4
//IL_0034: brtrue.s IL_003e
//IL_0036: ldloc.3
//IL_0037: ldloc.s V_4
//IL_0039: ldelem.i8
//IL_003a: ldc.i4.0
//IL_003b: conv.i8
//IL_003c: beq.s IL_007e
//IL_003e: ldloc.0
//IL_003f: ldloc.3
//IL_0040: ldloc.s V_4
//IL_0042: ldelem.i8
//IL_0043: and
//IL_0044: ldloc.3
//IL_0045: ldloc.s V_4
//IL_0047: ldelem.i8
//IL_0048: bne.un.s IL_0073
//IL_004a: ldloc.0
//IL_004b: ldloc.3
//IL_004c: ldloc.s V_4
//IL_004e: ldelem.i8
//IL_004f: sub
//IL_0050: stloc.0
//IL_0051: ldloc.s V_6
//IL_0053: brtrue.s IL_0063
//IL_0055: ldloc.s V_5
//IL_0057: ldc.i4.0
//IL_0058: ldstr ", "
//IL_005d: callvirt instance class System.Text.StringBuilder System.Text.StringBuilder::Insert(int32,
//string)
//IL_0062: pop
//IL_0063: ldloc.s V_5
//IL_0065: ldc.i4.0
//IL_0066: ldloc.2
//IL_0067: ldloc.s V_4
//IL_0069: ldelem.ref
//IL_006a: callvirt instance class System.Text.StringBuilder System.Text.StringBuilder::Insert(int32,
//string)
//IL_006f: pop
//IL_0070: ldc.i4.0
//IL_0071: stloc.s V_6
//IL_0073: ldloc.s V_4
//IL_0075: ldc.i4.1
//IL_0076: sub
//IL_0077: stloc.s V_4
//IL_0079: ldloc.s V_4
//IL_007b: ldc.i4.0
//IL_007c: bge.s IL_0032
//IL_007e: ldloc.0
//IL_007f: ldc.i4.0
//IL_0080: conv.i8
//IL_0081: beq.s IL_008a
//IL_0083: ldarg.1
//IL_0084: callvirt instance string System.Object::ToString()
//IL_0089: ret
//IL_008a: ldloc.s V_7
//IL_008c: ldc.i4.0
//IL_008d: conv.i8
//IL_008e: bne.un.s IL_00a1
//IL_0090: ldloc.3
//IL_0091: ldc.i4.0
//IL_0092: ldelem.i8
//IL_0093: ldc.i4.0
//IL_0094: conv.i8
//IL_0095: bne.un.s IL_009b
//IL_0097: ldloc.2
//IL_0098: ldc.i4.0
//IL_0099: ldelem.ref
//IL_009a: ret
//IL_009b: ldstr "0"
//IL_00a0: ret
//IL_00a1: ldloc.s V_5
//IL_00a3: callvirt instance string System.Object::ToString()
//IL_00a8: ret
ulong V_0;
System.Enum.HashEntry V_1;
string[] V_2;
ulong[] V_3;
int V_4;
System.Text.StringBuilder V_5;
bool V_6;
ulong V_7;
V_0 = System.Enum.ToUInt64(@value);
V_1 = System.Enum.GetHashEntry(eT);
V_2 = V_1.names;
V_3 = V_1.values;
V_4 = V_3.Length - 1;
V_5 = new System.Text.StringBuilder();
V_6 = true;
V_7 = V_0;
//直接跳往IL_0079
while(V_4>=0)
{
//IL_0032
if (V_4 == 0)//不满足跳往IL_003e
{
//IL_0036
if (V_3[V_4] == 0)//不满足跳往IL_003e
{
//IL_007e
if(V_0==0)
{
//IL_008a
if (V_7 == 0)
{
if (V_3[0] == 0)
{
return V_2[0];
}
else
{
return "0";
}
}
else
{
return V_5.ToString();
}
}
else
{
return @value.ToString();
}
}
}
//IL_003e
if (V_0 & V_3[V_4] == V_3[V_4])//不满足跳往IL_0073
{
V_0 = V_0 - V_3[V_4];
if (!V_6)//不满足跳往IL_0063
{
V_5.Insert(0, ", ");
//IL_0063
}
//IL_0063
V_5.Insert(0, V_2[V_4]);
V_6 = false;
//IL_0073
}
//IL_0073
V_4 = V_4 - 1;
//IL_0079
continue;
}
if(V_0==0)
{
//IL_008a
if (V_7 == 0)
{
if (V_3[0] == 0)
{
return V_2[0];
}
else
{
return "0";
}
}
else
{
return V_5.ToString();
}
}
else
{
return @value.ToString();
}
}
/// <summary>
/// 对带符号类型进行符号扩展然后将其值当做ulong解析,例如-1会被解析为2^64-1
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
private static ulong ToUInt64(object @value)
{
//.maxstack 2
//.locals init (valuetype System.TypeCode V_0,
//uint64 V_1,
//valuetype System.TypeCode V_2)
//IL_0000: ldarg.0
//IL_0001: call valuetype System.TypeCode System.Convert::GetTypeCode(object)
//IL_0006: stloc.0
//IL_0007: ldloc.0
//IL_0008: stloc.2
//IL_0009: ldloc.2
//IL_000a: ldc.i4.5
//IL_000b: sub
//IL_000c: switch (
//IL_0033,
//IL_0041,
//IL_0033,
//IL_0041,
//IL_0033,
//IL_0041,
//IL_0033,
//IL_0041)
//IL_0031: br.s IL_004f
//IL_0033: ldarg.0
//IL_0034: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_InvariantCulture()
//IL_0039: call int64 System.Convert::ToInt64(object,
//class System.IFormatProvider)
//IL_003e: stloc.1
//IL_003f: br.s IL_005f
//IL_0041: ldarg.0
//IL_0042: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_InvariantCulture()
//IL_0047: call uint64 System.Convert::ToUInt64(object,
//class System.IFormatProvider)
//IL_004c: stloc.1
//IL_004d: br.s IL_005f
//IL_004f: ldstr "InvalidOperation_UnknownEnumType"
//IL_0054: call string System.Environment::GetResourceString(string)
//IL_0059: newobj instance void System.InvalidOperationException::.ctor(string)
//IL_005e: throw
//IL_005f: ldloc.1
//IL_0060: ret
System.TypeCode V_0;
ulong V_1;
System.TypeCode V_2;
V_0=System.Convert.GetTypeCode(eT);
V_2=V_0;
switch (V_2)
{
case TypeCode.SByte:
case TypeCode.Int16:
case TypeCode.Int32:
case TypeCode.Int64:
{
V_1 = (ulong)System.Convert.ToInt64(@value, CultureInfo.InvariantCulture);
break;
}
case TypeCode.Byte:
case TypeCode.UInt16:
case TypeCode.UInt32:
case TypeCode.UInt64:
{
V_1 = System.Convert.ToUInt64(@value, CultureInfo.InvariantCulture);
break;
}
default:
throw new System.InvalidOperationException(System.Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
}
return V_1;
}
/// <summary>
/// 要注意,查询失败返回的int为负数,但是很多情况下并不是-1,所以判断查询失败时,需要谨慎使用==-1条件。
/// </summary>
/// <param name="array"></param>
/// <param name="value"></param>
/// <returns></returns>
private static int BinarySearch(ulong[] @array, ulong @value)
{
//.maxstack 2
//.locals init (int32 V_0,
//int32 V_1,
//int32 V_2,
//uint64 V_3)
//IL_0000: ldc.i4.0
//IL_0001: stloc.0
//IL_0002: ldarg.0
//IL_0003: ldlen
//IL_0004: conv.i4
//IL_0005: ldc.i4.1
//IL_0006: sub
//IL_0007: stloc.1
//IL_0008: br.s IL_0028
//IL_000a: ldloc.0
//IL_000b: ldloc.1
//IL_000c: add
//IL_000d: ldc.i4.1
//IL_000e: shr
//IL_000f: stloc.2
//IL_0010: ldarg.0
//IL_0011: ldloc.2
//IL_0012: ldelem.i8
//IL_0013: stloc.3
//IL_0014: ldarg.1
//IL_0015: ldloc.3
//IL_0016: bne.un.s IL_001a
//IL_0018: ldloc.2
//IL_0019: ret
//IL_001a: ldloc.3
//IL_001b: ldarg.1
//IL_001c: bge.un.s IL_0024
//IL_001e: ldloc.2
//IL_001f: ldc.i4.1
//IL_0020: add
//IL_0021: stloc.0
//IL_0022: br.s IL_0028
//IL_0024: ldloc.2
//IL_0025: ldc.i4.1
//IL_0026: sub
//IL_0027: stloc.1
//IL_0028: ldloc.0
//IL_0029: ldloc.1
//IL_002a: ble.s IL_000a
//IL_002c: ldloc.0
//IL_002d: not
//IL_002e: ret
int V_0, V_1, V_2;
ulong V_3;
V_0 = 0;
V_1 = @array.Length - 1;
//IL_0028
if (V_0 <= V_1)
{
while (true)
{
//IL_000a
V_2 = (V_0 + V_1) >> 1;
V_3 = @array[V_2];
if (@value == V_3)
{
return V_2;
}
else
{
//IL_001a
if (V_3 < @value)
{
V_0 = V_2 + 1;
//IL_0028
}
else
{
//IL_0024
V_1 = V_2 - 1;
//IL_0028
}
//IL_0028
if (V_0 <= V_1)
{
//IL_000a
continue;
}
else
{
return ~V_0;
}
}
}
}
else
{
return ~V_0;
}
}
[MethodImpl(MethodImplAttributes.InternalCall)]
private static int InternalCompareTo(object o1, object o2)
{
//internalcall
}
[MethodImpl(MethodImplAttributes.InternalCall)]
private static System.Type InternalGetUnderlyingType( System.Type enumType)
{
//internalcall
}
[MethodImpl(MethodImplAttributes.InternalCall)]
private static void InternalGetEnumValues( System.Type enumType,ref ulong[] values,ref string[] names)
{
//internalcall
}
[MethodImpl(MethodImplAttributes.InternalCall)]
private static object InternalBoxEnum( System.Type enumType, long @value)
{
//internalcall
}
[ComVisible(true)]
public static object Parse( System.Type enumType, string @value)
{
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: ldarg.1
//IL_0002: ldc.i4.0
//IL_0003: call object System.Enum::Parse(class System.Type,
//string,
//bool)
//IL_0008: ret
return System.Enum.Parse(enumType, @value, false);
}
[ComVisible(true)]
public static object Parse( System.Type enumType, string @value, bool ignoreCase)
{
//.maxstack 5
//.locals init (uint64 V_0,
//class System.Type V_1,
//object V_2,
//string[] V_3,
//class System.Enum/HashEntry V_4,
//string[] V_5,
//int32 V_6,
//bool V_7,
//int32 V_8,
//uint64 V_9,
//object V_10,
//object[] V_11)
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.1
//IL_0049: brtrue.s IL_0056
//IL_004b: ldstr "value"
//IL_0050: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_0055: throw
//IL_0056: ldarg.1
//IL_0057: callvirt instance string System.String::Trim()
//IL_005c: starg.s 'value'
//IL_005e: ldarg.1
//IL_005f: callvirt instance int32 System.String::get_Length()
//IL_0064: brtrue.s IL_0076
//IL_0066: ldstr "Arg_MustContainEnumInfo"
//IL_006b: call string System.Environment::GetResourceString(string)
//IL_0070: newobj instance void System.ArgumentException::.ctor(string)
//IL_0075: throw
//IL_0076: ldc.i4.0
//IL_0077: conv.i8
//IL_0078: stloc.0
//IL_0079: ldarg.1
//IL_007a: ldc.i4.0
//IL_007b: callvirt instance char System.String::get_Chars(int32)
//IL_0080: call bool System.Char::IsDigit(char)
//IL_0085: brtrue.s IL_009d
//IL_0087: ldarg.1
//IL_0088: ldc.i4.0
//IL_0089: callvirt instance char System.String::get_Chars(int32)
//IL_008e: ldc.i4.s 45
//IL_0090: beq.s IL_009d
//IL_0092: ldarg.1
//IL_0093: ldc.i4.0
//IL_0094: callvirt instance char System.String::get_Chars(int32)
//IL_0099: ldc.i4.s 43
//IL_009b: bne.un.s IL_00c2
//IL_009d: ldarg.0
//IL_009e: call class System.Type System.Enum::GetUnderlyingType(class System.Type)
//IL_00a3: stloc.1
//.try
//{
//IL_00a4: ldarg.1
//IL_00a5: ldloc.1
//IL_00a6: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_InvariantCulture()
//IL_00ab: call object System.Convert::ChangeType(object,
//class System.Type,
//class System.IFormatProvider)
//IL_00b0: stloc.2
//IL_00b1: ldarg.0
//IL_00b2: ldloc.2
//IL_00b3: call object System.Enum::ToObject(class System.Type,
//object)
//IL_00b8: stloc.s V_10
//IL_00ba: leave IL_018b
//}
//catch System.FormatException
//{
//IL_00bf: pop
//IL_00c0: leave.s IL_00c2
//}
//IL_00c2: ldarg.1
//IL_00c3: ldsfld char[] System.Enum::enumSeperatorCharArray
//IL_00c8: callvirt instance string[] System.String::Split(char[])
//IL_00cd: stloc.3
//IL_00ce: ldarg.0
//IL_00cf: call class System.Enum/HashEntry System.Enum::GetHashEntry(class System.Type)
//IL_00d4: stloc.s V_4
//IL_00d6: ldloc.s V_4
//IL_00d8: ldfld string[] System.Enum/HashEntry::names
//IL_00dd: stloc.s V_5
//IL_00df: ldc.i4.0
//IL_00e0: stloc.s V_6
//IL_00e2: br IL_0179
//IL_00e7: ldloc.3
//IL_00e8: ldloc.s V_6
//IL_00ea: ldloc.3
//IL_00eb: ldloc.s V_6
//IL_00ed: ldelem.ref
//IL_00ee: callvirt instance string System.String::Trim()
//IL_00f3: stelem.ref
//IL_00f4: ldc.i4.0
//IL_00f5: stloc.s V_7
//IL_00f7: ldc.i4.0
//IL_00f8: stloc.s V_8
//IL_00fa: br.s IL_013e
//IL_00fc: ldarg.2
//IL_00fd: brfalse.s IL_0112
//IL_00ff: ldloc.s V_5
//IL_0101: ldloc.s V_8
//IL_0103: ldelem.ref
//IL_0104: ldloc.3
//IL_0105: ldloc.s V_6
//IL_0107: ldelem.ref
//IL_0108: ldc.i4.5
//IL_0109: call int32 System.String::Compare(string,
//string,
//valuetype System.StringComparison)
//IL_010e: brfalse.s IL_0122
//IL_0110: br.s IL_0138
//IL_0112: ldloc.s V_5
//IL_0114: ldloc.s V_8
//IL_0116: ldelem.ref
//IL_0117: ldloc.3
//IL_0118: ldloc.s V_6
//IL_011a: ldelem.ref
//IL_011b: callvirt instance bool System.String::Equals(string)
//IL_0120: brfalse.s IL_0138
//IL_0122: ldloc.s V_4
//IL_0124: ldfld uint64[] System.Enum/HashEntry::values
//IL_0129: ldloc.s V_8
//IL_012b: ldelem.i8
//IL_012c: stloc.s V_9
//IL_012e: ldloc.0
//IL_012f: ldloc.s V_9
//IL_0131: or
//IL_0132: stloc.0
//IL_0133: ldc.i4.1
//IL_0134: stloc.s V_7
//IL_0136: br.s IL_0146
//IL_0138: ldloc.s V_8
//IL_013a: ldc.i4.1
//IL_013b: add
//IL_013c: stloc.s V_8
//IL_013e: ldloc.s V_8
//IL_0140: ldloc.s V_5
//IL_0142: ldlen
//IL_0143: conv.i4
//IL_0144: blt.s IL_00fc
//IL_0146: ldloc.s V_7
//IL_0148: brtrue.s IL_0173
//IL_014a: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_014f: ldstr "Arg_EnumValueNotFound"
//IL_0154: call string System.Environment::GetResourceString(string)
//IL_0159: ldc.i4.1
//IL_015a: newarr System.Object
//IL_015f: stloc.s V_11
//IL_0161: ldloc.s V_11
//IL_0163: ldc.i4.0
//IL_0164: ldarg.1
//IL_0165: stelem.ref
//IL_0166: ldloc.s V_11
//IL_0168: call string System.String::Format(class System.IFormatProvider,
//string,
//object[])
//IL_016d: newobj instance void System.ArgumentException::.ctor(string)
//IL_0172: throw
//IL_0173: ldloc.s V_6
//IL_0175: ldc.i4.1
//IL_0176: add
//IL_0177: stloc.s V_6
//IL_0179: ldloc.s V_6
//IL_017b: ldloc.3
//IL_017c: ldlen
//IL_017d: conv.i4
//IL_017e: blt IL_00e7
//IL_0183: ldarg.0
//IL_0184: ldloc.0
//IL_0185: call object System.Enum::ToObject(class System.Type,
//uint64)
//IL_018a: ret
//IL_018b: ldloc.s V_10
//IL_018d: ret
ulong V_0;
System.Type V_1;
object V_2;
string[] V_3;
System.Enum.HashEntry V_4;
string[] V_5;
int V_6;
bool V_7;
int V_8;
ulong V_9;
object V_10;
object[] V_11;
if(enumType==null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
//IL_000e
if(enumType as System.RuntimeType==null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"),"enumType");
}
else
{
//IL_002b
if(enumType.IsEnum)
{
//IL_0048
if(@value==null)
{
throw new System.ArgumentNullException("value");
}
else
{
@value=@value.Trim();
if(@value.Length==0)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustContainEnumInfo"));
}
else
{
//IL_0076
V_0=0;
if (System.Char.IsDigit(@value[0]) || @value[0] == '-' || @value[0] != '+')
{
//IL_009d
V_1 = System.Enum.GetUnderlyingType(enumType);
try
{
V_2 = System.Convert.ChangeType(@value, V_1, CultureInfo.InvariantCulture);
V_10 = System.Enum.ToObject(enumType, V_2);
return V_10;
}
catch(System.FormatException)
{
//跳往IL_00c2
}
}
else
{
//IL_00c2
}
//IL_00c2
V_3 = @value.Split(System.Enum.enumSeperatorCharArray);
V_4 = System.Enum.GetHashEntry(enumType);
V_5 = V_4.names;
V_6 = 0;
//直接跳往IL_0179
while(V_6<V_3.Length)
{
//IL_00e7
V_3[V_6] = V_3[V_6].Trim();
V_7 = false;
V_8 = 0;
//直接跳往IL_013e
while(V_8<V_5.Length)
{
//IL_00fc
if(ignoreCase)
{
if(string.Compare(V_5[8],V_3[8],System.StringComparison.OrdinalIgnoreCase))
{
//IL_0138
V_8 += 1;
//IL_013e
continue;
}
else
{
//IL_0122
}
}
else
{
//IL_0112
if(V_5[V_8].Equals(V_3[V_6]))
{
//IL_0122
}
else
{
//IL_0138
V_8 += 1;
//IL_013e
continue;
}
}
//IL_0122
V_9 = V_4.values[V_8];
V_0 = V_0 | V_9;
V_7 = true;
//直接跳往IL_0146
break;
}
//IL_0146
if (V_7)//IL_0148
{
//IL_0173
V_6 += 1;
//IL_0179
continue;
}
else
{
V_11 = new object[1];
V_11[0] = @value;
throw new System.ArgumentException(string.Format(CultureInfo.CurrentCulture, System.Environment.GetResourceString("Arg_EnumValueNotFound"), V_11));
}
}
return System.Enum.ToObject(enumType, V_0);
}
}
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"),"enumType");
}
}
}
}
[ComVisible(true)]
public static System.Type GetUnderlyingType( System.Type enumType)
{
//System.Runtime.InteropServices.ComVisibleAttribute(true)
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.Reflection.Emit.EnumBuilder
//IL_0014: brfalse.s IL_0022
//IL_0016: ldarg.0
//IL_0017: castclass System.Reflection.Emit.EnumBuilder
//IL_001c: callvirt instance class System.Type System.Type::get_UnderlyingSystemType()
//IL_0021: ret
//IL_0022: ldarg.0
//IL_0023: isinst System.RuntimeType
//IL_0028: brtrue.s IL_003f
//IL_002a: ldstr "Arg_MustBeType"
//IL_002f: call string System.Environment::GetResourceString(string)
//IL_0034: ldstr "enumType"
//IL_0039: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_003e: throw
//IL_003f: ldarg.0
//IL_0040: callvirt instance bool System.Type::get_IsEnum()
//IL_0045: brtrue.s IL_005c
//IL_0047: ldstr "Arg_MustBeEnum"
//IL_004c: call string System.Environment::GetResourceString(string)
//IL_0051: ldstr "enumType"
//IL_0056: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_005b: throw
//IL_005c: ldarg.0
//IL_005d: call class System.Type System.Enum::InternalGetUnderlyingType(class System.Type)
//IL_0062: ret
if(enumType==null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if(enumType as System.Reflection.Emit.EnumBuilder==null)
{
//IL_0022
if(enumType as System.RuntimeType==null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"),"enumType");
}
else
{
//IL_003f
if (enumType.IsEnum)
{
return System.Enum.InternalGetUnderlyingType(enumType);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
else
{
return((System.Reflection.Emit.EnumBuilder)enumType).UnderlyingSystemType;
}
}
}
[ComVisible(true)]
public static System.Array GetValues( System.Type enumType)
{
//.maxstack 3
//.locals init (uint64[] V_0,
//class System.Array V_1,
//int32 V_2,
//object V_3)
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: call class System.Enum/HashEntry System.Enum::GetHashEntry(class System.Type)
//IL_004e: ldfld uint64[] System.Enum/HashEntry::values
//IL_0053: stloc.0
//IL_0054: ldarg.0
//IL_0055: ldloc.0
//IL_0056: ldlen
//IL_0057: conv.i4
//IL_0058: call class System.Array System.Array::CreateInstance(class System.Type,
//int32)
//IL_005d: stloc.1
//IL_005e: ldc.i4.0
//IL_005f: stloc.2
//IL_0060: br.s IL_0078
//IL_0062: ldarg.0
//IL_0063: ldloc.0
//IL_0064: ldloc.2
//IL_0065: ldelem.i8
//IL_0066: call object System.Enum::ToObject(class System.Type,
//uint64)
//IL_006b: stloc.3
//IL_006c: ldloc.1
//IL_006d: ldloc.3
//IL_006e: ldloc.2
//IL_006f: callvirt instance void System.Array::SetValue(object,
//int32)
//IL_0074: ldloc.2
//IL_0075: ldc.i4.1
//IL_0076: add
//IL_0077: stloc.2
//IL_0078: ldloc.2
//IL_0079: ldloc.0
//IL_007a: ldlen
//IL_007b: conv.i4
//IL_007c: blt.s IL_0062
//IL_007e: ldloc.1
//IL_007f: ret
ulong[] V_0;
System.Array V_1;
int V_2;
object V_3;
if(enumType==null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if(enumType as System.RuntimeType==null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"),"enumType");
}
else
{
//IL_002b
if (enumType.IsEnum)
{
//IL_0048
V_0 = System.Enum.GetHashEntry(enumType).values;
V_1 = System.Array.CreateInstance(enumType, V_0.Length);
//直接跳往IL_0078
for (V_2 = 0;/*IL_005e*/V_2 < V_0.Length;/*IL_0078*/V_2 += 1/*IL_0074*/)//满足条件跳往IL_0062
{
//IL_0062
V_3 = System.Enum.ToObject(enumType, V_0[V_2]);
V_1.SetValue(V_3, V_2);
//IL_0078
}
return V_1;
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
[ComVisible(true)]
public static string GetName( System.Type enumType, object @value)
{
//.maxstack 3
//.locals init (class System.Type V_0)
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.1
//IL_0049: brtrue.s IL_0056
//IL_004b: ldstr "value"
//IL_0050: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_0055: throw
//IL_0056: ldarg.1
//IL_0057: callvirt instance class System.Type System.Object::GetType()
//IL_005c: stloc.0
//IL_005d: ldloc.0
//IL_005e: callvirt instance bool System.Type::get_IsEnum()
//IL_0063: brtrue.s IL_00c8
//IL_0065: ldloc.0
//IL_0066: ldsfld class System.Type System.Enum::intType
//IL_006b: beq.s IL_00c8
//IL_006d: ldloc.0
//IL_006e: ldtoken System.Int16
//IL_0073: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0078: beq.s IL_00c8
//IL_007a: ldloc.0
//IL_007b: ldtoken System.UInt16
//IL_0080: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0085: beq.s IL_00c8
//IL_0087: ldloc.0
//IL_0088: ldtoken System.Byte
//IL_008d: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0092: beq.s IL_00c8
//IL_0094: ldloc.0
//IL_0095: ldtoken System.SByte
//IL_009a: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_009f: beq.s IL_00c8
//IL_00a1: ldloc.0
//IL_00a2: ldtoken System.UInt32
//IL_00a7: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_00ac: beq.s IL_00c8
//IL_00ae: ldloc.0
//IL_00af: ldtoken System.Int64
//IL_00b4: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_00b9: beq.s IL_00c8
//IL_00bb: ldloc.0
//IL_00bc: ldtoken System.UInt64
//IL_00c1: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_00c6: bne.un.s IL_00d0
//IL_00c8: ldarg.0
//IL_00c9: ldarg.1
//IL_00ca: call string System.Enum::InternalGetValueAsString(class System.Type,
//object)
//IL_00cf: ret
//IL_00d0: ldstr "Arg_MustBeEnumBaseTypeOrEnum"
//IL_00d5: call string System.Environment::GetResourceString(string)
//IL_00da: ldstr "value"
//IL_00df: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_00e4: throw
System.Type V_0;
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
//IL_002b
if (enumType.IsEnum)
{
//IL_0048
if(@value==null)
{
throw new System.ArgumentNullException("value");
}
else
{
V_0=@value.GetType();
if (V_0.IsEnum || V_0 == System.Enum.intType || V_0 == typeof(short) || V_0 == typeof(ushort) || V_0 == typeof(byte) || V_0 == typeof(sbyte) || V_0 == typeof(uint) || V_0 == typeof(long) || V_0 == typeof(ulong))
{
//IL_00c8
return System.Enum.InternalGetValueAsString(enumType, @value);
}
else
{
//IL_00d0
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value");
}
}
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
[ComVisible(true)]
public static string[] GetNames( System.Type enumType)
{
//.maxstack 3
//.locals init (string[] V_0,
//string[] V_1)
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: call class System.Enum/HashEntry System.Enum::GetHashEntry(class System.Type)
//IL_004e: ldfld string[] System.Enum/HashEntry::names
//IL_0053: stloc.0
//IL_0054: ldloc.0
//IL_0055: ldlen
//IL_0056: conv.i4
//IL_0057: newarr System.String
//IL_005c: stloc.1
//IL_005d: ldloc.0
//IL_005e: ldloc.1
//IL_005f: ldloc.0
//IL_0060: ldlen
//IL_0061: conv.i4
//IL_0062: call void System.Array::Copy(class System.Array,
//class System.Array,
//int32)
//IL_0067: ldloc.1
//IL_0068: ret
string[] V_0, V_1;
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
//IL_002b
if (enumType.IsEnum)
{
//IL_0048
V_0 = System.Enum.GetHashEntry(enumType).names;
V_1 = new string[V_0.Length];
System.Array.Copy(V_0, V_1, V_0.Length);
return V_1;
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
[ComVisible(true)]
public static object ToObject( System.Type enumType, object @value)
{
//.maxstack 3
//.locals init (valuetype System.TypeCode V_0,
//valuetype System.TypeCode V_1)
//IL_0000: ldarg.1
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "value"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.1
//IL_000f: call valuetype System.TypeCode System.Convert::GetTypeCode(object)
//IL_0014: stloc.0
//IL_0015: ldloc.0
//IL_0016: stloc.1
//IL_0017: ldloc.1
//IL_0018: ldc.i4.5
//IL_0019: sub
//IL_001a: switch (
//IL_004e,
//IL_0082,
//IL_005b,
//IL_008f,
//IL_0041,
//IL_0075,
//IL_0068,
//IL_009c)
//IL_003f: br.s IL_00a9
//IL_0041: ldarg.0
//IL_0042: ldarg.1
//IL_0043: unbox.any System.Int32
//IL_0048: call object System.Enum::ToObject(class System.Type,
//int32)
//IL_004d: ret
//IL_004e: ldarg.0
//IL_004f: ldarg.1
//IL_0050: unbox.any System.SByte
//IL_0055: call object System.Enum::ToObject(class System.Type,
//int8)
//IL_005a: ret
//IL_005b: ldarg.0
//IL_005c: ldarg.1
//IL_005d: unbox.any System.Int16
//IL_0062: call object System.Enum::ToObject(class System.Type,
//int16)
//IL_0067: ret
//IL_0068: ldarg.0
//IL_0069: ldarg.1
//IL_006a: unbox.any System.Int64
//IL_006f: call object System.Enum::ToObject(class System.Type,
//int64)
//IL_0074: ret
//IL_0075: ldarg.0
//IL_0076: ldarg.1
//IL_0077: unbox.any System.UInt32
//IL_007c: call object System.Enum::ToObject(class System.Type,
//uint32)
//IL_0081: ret
//IL_0082: ldarg.0
//IL_0083: ldarg.1
//IL_0084: unbox.any System.Byte
//IL_0089: call object System.Enum::ToObject(class System.Type,
//uint8)
//IL_008e: ret
//IL_008f: ldarg.0
//IL_0090: ldarg.1
//IL_0091: unbox.any System.UInt16
//IL_0096: call object System.Enum::ToObject(class System.Type,
//uint16)
//IL_009b: ret
//IL_009c: ldarg.0
//IL_009d: ldarg.1
//IL_009e: unbox.any System.UInt64
//IL_00a3: call object System.Enum::ToObject(class System.Type,
//uint64)
//IL_00a8: ret
//IL_00a9: ldstr "Arg_MustBeEnumBaseTypeOrEnum"
//IL_00ae: call string System.Environment::GetResourceString(string)
//IL_00b3: ldstr "value"
//IL_00b8: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_00bd: throw
System.TypeCode V_0,V_1;
if(@value==null)
{
throw new System.ArgumentNullException("value");
}
else
{
V_0=System.Convert.GetTypeCode(@value);
V_1=V_0;
switch(V_1)
{
case TypeCode.SByte:
return System.Enum.ToObject(enumType,(sbyte)@value);
case TypeCode.Byte:
return System.Enum.ToObject(enumType, (byte)@value);
case TypeCode.Int16:
return System.Enum.ToObject(enumType, (short)@value);
case TypeCode.UInt16:
return System.Enum.ToObject(enumType, (ushort)@value);
case TypeCode.Int32:
return System.Enum.ToObject(enumType, (int)@value);
case TypeCode.UInt32:
return System.Enum.ToObject(enumType, (uint)@value);
case TypeCode.Int64:
return System.Enum.ToObject(enumType, (long)@value);
case TypeCode.UInt64:
return System.Enum.ToObject(enumType, (ulong)@value);
default:
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnumBaseTypeOrEnum"), "value");
}
}
}
[ComVisible(true)]
public static bool IsDefined( System.Type enumType, object @value)
{
//.maxstack 5
//.locals init (class System.Type V_0,
//class System.Type V_1,
//class System.Type V_2,
//string[] V_3,
//int32 V_4,
//uint64[] V_5,
//uint64 V_6,
//object[] V_7,
//object[] V_8)
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.1
//IL_0049: brtrue.s IL_0056
//IL_004b: ldstr "value"
//IL_0050: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_0055: throw
//IL_0056: ldarg.1
//IL_0057: callvirt instance class System.Type System.Object::GetType()
//IL_005c: stloc.0
//IL_005d: ldloc.0
//IL_005e: isinst System.RuntimeType
//IL_0063: brtrue.s IL_007a
//IL_0065: ldstr "Arg_MustBeType"
//IL_006a: call string System.Environment::GetResourceString(string)
//IL_006f: ldstr "valueType"
//IL_0074: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0079: throw
//IL_007a: ldarg.0
//IL_007b: call class System.Type System.Enum::GetUnderlyingType(class System.Type)
//IL_0080: stloc.1
//IL_0081: ldloc.0
//IL_0082: callvirt instance bool System.Type::get_IsEnum()
//IL_0087: brfalse.s IL_00d0
//IL_0089: ldloc.0
//IL_008a: call class System.Type System.Enum::GetUnderlyingType(class System.Type)
//IL_008f: stloc.2
//IL_0090: ldloc.0
//IL_0091: ldarg.0
//IL_0092: beq.s IL_00cc
//IL_0094: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_0099: ldstr "Arg_EnumAndObjectMustBeSameType"
//IL_009e: call string System.Environment::GetResourceString(string)
//IL_00a3: ldc.i4.2
//IL_00a4: newarr System.Object
//IL_00a9: stloc.s V_7
//IL_00ab: ldloc.s V_7
//IL_00ad: ldc.i4.0
//IL_00ae: ldloc.0
//IL_00af: callvirt instance string System.Object::ToString()
//IL_00b4: stelem.ref
//IL_00b5: ldloc.s V_7
//IL_00b7: ldc.i4.1
//IL_00b8: ldarg.0
//IL_00b9: callvirt instance string System.Object::ToString()
//IL_00be: stelem.ref
//IL_00bf: ldloc.s V_7
//IL_00c1: call string System.String::Format(class System.IFormatProvider,
//string,
//object[])
//IL_00c6: newobj instance void System.ArgumentException::.ctor(string)
//IL_00cb: throw
//IL_00cc: ldloc.2
//IL_00cd: stloc.0
//IL_00ce: br.s IL_0114
//IL_00d0: ldloc.0
//IL_00d1: ldloc.1
//IL_00d2: beq.s IL_0114
//IL_00d4: ldloc.0
//IL_00d5: ldsfld class System.Type System.Enum::stringType
//IL_00da: beq.s IL_0114
//IL_00dc: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_00e1: ldstr "Arg_EnumUnderlyingTypeAndObjectMustBeSameType"
//IL_00e6: call string System.Environment::GetResourceString(string)
//IL_00eb: ldc.i4.2
//IL_00ec: newarr System.Object
//IL_00f1: stloc.s V_8
//IL_00f3: ldloc.s V_8
//IL_00f5: ldc.i4.0
//IL_00f6: ldloc.0
//IL_00f7: callvirt instance string System.Object::ToString()
//IL_00fc: stelem.ref
//IL_00fd: ldloc.s V_8
//IL_00ff: ldc.i4.1
//IL_0100: ldloc.1
//IL_0101: callvirt instance string System.Object::ToString()
//IL_0106: stelem.ref
//IL_0107: ldloc.s V_8
//IL_0109: call string System.String::Format(class System.IFormatProvider,
//string,
//object[])
//IL_010e: newobj instance void System.ArgumentException::.ctor(string)
//IL_0113: throw
//IL_0114: ldloc.0
//IL_0115: ldsfld class System.Type System.Enum::stringType
//IL_011a: bne.un.s IL_014f
//IL_011c: ldarg.0
//IL_011d: call class System.Enum/HashEntry System.Enum::GetHashEntry(class System.Type)
//IL_0122: ldfld string[] System.Enum/HashEntry::names
//IL_0127: stloc.3
//IL_0128: ldc.i4.0
//IL_0129: stloc.s V_4
//IL_012b: br.s IL_0146
//IL_012d: ldloc.3
//IL_012e: ldloc.s V_4
//IL_0130: ldelem.ref
//IL_0131: ldarg.1
//IL_0132: castclass System.String
//IL_0137: callvirt instance bool System.String::Equals(string)
//IL_013c: brfalse.s IL_0140
//IL_013e: ldc.i4.1
//IL_013f: ret
//IL_0140: ldloc.s V_4
//IL_0142: ldc.i4.1
//IL_0143: add
//IL_0144: stloc.s V_4
//IL_0146: ldloc.s V_4
//IL_0148: ldloc.3
//IL_0149: ldlen
//IL_014a: conv.i4
//IL_014b: blt.s IL_012d
//IL_014d: ldc.i4.0
//IL_014e: ret
//IL_014f: ldarg.0
//IL_0150: call class System.Enum/HashEntry System.Enum::GetHashEntry(class System.Type)
//IL_0155: ldfld uint64[] System.Enum/HashEntry::values
//IL_015a: stloc.s V_5
//IL_015c: ldloc.0
//IL_015d: ldsfld class System.Type System.Enum::intType
//IL_0162: beq.s IL_01bf
//IL_0164: ldloc.0
//IL_0165: ldtoken System.Int16
//IL_016a: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_016f: beq.s IL_01bf
//IL_0171: ldloc.0
//IL_0172: ldtoken System.UInt16
//IL_0177: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_017c: beq.s IL_01bf
//IL_017e: ldloc.0
//IL_017f: ldtoken System.Byte
//IL_0184: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0189: beq.s IL_01bf
//IL_018b: ldloc.0
//IL_018c: ldtoken System.SByte
//IL_0191: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0196: beq.s IL_01bf
//IL_0198: ldloc.0
//IL_0199: ldtoken System.UInt32
//IL_019e: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_01a3: beq.s IL_01bf
//IL_01a5: ldloc.0
//IL_01a6: ldtoken System.Int64
//IL_01ab: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_01b0: beq.s IL_01bf
//IL_01b2: ldloc.0
//IL_01b3: ldtoken System.UInt64
//IL_01b8: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_01bd: bne.un.s IL_01d7
//IL_01bf: ldarg.1
//IL_01c0: call uint64 System.Enum::ToUInt64(object)
//IL_01c5: stloc.s V_6
//IL_01c7: ldloc.s V_5
//IL_01c9: ldloc.s V_6
//IL_01cb: call int32 System.Enum::BinarySearch(uint64[],
//uint64)
//IL_01d0: ldc.i4.0
//IL_01d1: clt
//IL_01d3: ldc.i4.0
//IL_01d4: ceq
//IL_01d6: ret
//IL_01d7: ldstr "InvalidOperation_UnknownEnumType"
//IL_01dc: call string System.Environment::GetResourceString(string)
//IL_01e1: newobj instance void System.InvalidOperationException::.ctor(string)
//IL_01e6: throw
System.Type V_0, V_1, V_2;
string[] V_3;
int V_4;
ulong[] V_5;
ulong V_6;
object[] V_7, V_8;
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
//IL_002b
if (enumType.IsEnum)
{
//IL_0048
if (@value == null)
{
throw new System.ArgumentNullException("value");
}
else
{
V_0 = @value.GetType();
//IL_005d
if(V_0 as System.RuntimeType==null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "valueType");
}
else
{
//IL_007a
V_1=System.Enum.GetUnderlyingType(enumType);
if(V_0.IsEnum)
{
V_2=System.Enum.GetUnderlyingType(V_0);
if(V_0==enumType)
{
//IL_00cc
V_0 = V_2;
//直接跳往IL_0114
if (V_0 == System.Enum.stringType)
{
//IL_011c
V_3 = System.Enum.GetHashEntry(enumType).names;
V_4 = 0;
//直接跳往IL_0146
while (V_4 < V_3.Length)
{
//IL_012d
if (V_3[V_4].Equals((string)@value))
{
return true;
}
else
{
//IL_0140
V_4 += 1;
//IL_0146
continue;
}
}
return false;
}
else
{
//IL_014f
V_5 = System.Enum.GetHashEntry(enumType).values;
if (V_0 == System.Enum.intType || V_0 == typeof(short) || V_0 == typeof(ushort) || V_0 == typeof(byte) || V_0 == typeof(sbyte) || V_0 == typeof(uint) || V_0 == typeof(long) || V_0 == typeof(ulong))
{
//IL_01bf
V_6 = System.Enum.ToUInt64(@value);
return (System.Enum.BinarySearch(V_5, V_6) < 0) == false;
}
else
{
//IL_01d7
throw new System.InvalidOperationException(System.Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
}
}
}
else
{
//IL_0094
V_7 = new object[2];
V_7[0] = V_0.ToString();
V_7[1] = enumType.ToString();
throw new System.ArgumentException(string.Format(CultureInfo.CurrentCulture, System.Environment.GetResourceString("Arg_EnumAndObjectMustBeSameType"), V_7));
}
}
else
{
//IL_00d0
if (V_0 == V_1 || V_0 == System.Enum.stringType)
{
//IL_0114
if(V_0==System.Enum.stringType)
{
//IL_011c
V_3 = System.Enum.GetHashEntry(enumType).names;
V_4 = 0;
//直接跳往IL_0146
while(V_4<V_3.Length)
{
//IL_012d
if(V_3[V_4].Equals((string)@value))
{
return true;
}
else
{
//IL_0140
V_4 += 1;
//IL_0146
continue;
}
}
return false;
}
else
{
//IL_014f
V_5=System.Enum.GetHashEntry(enumType).values;
if (V_0 == System.Enum.intType || V_0 == typeof(short) || V_0 == typeof(ushort) || V_0 == typeof(byte) || V_0 == typeof(sbyte) || V_0 == typeof(uint) || V_0 == typeof(long) || V_0 == typeof(ulong))
{
//IL_01bf
V_6 = System.Enum.ToUInt64(@value);
return (System.Enum.BinarySearch(V_5, V_6) < 0) == false;
}
else
{
//IL_01d7
throw new System.InvalidOperationException(System.Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
}
}
}
else
{
//IL_00dc
V_8 = new object[2];
V_8[0] = V_0.ToString();
V_8[1] = V_1.ToString();
throw new System.ArgumentException(string.Format(CultureInfo.CurrentCulture, System.Environment.GetResourceString("Arg_EnumUnderlyingTypeAndObjectMustBeSameType"), V_8));
}
}
}
}
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
[ComVisible(true)]
public static string Format( System.Type enumType, object @value, string format)
{
//.maxstack 5
//.locals init (class System.Type V_0,
//class System.Type V_1,
//class System.Type V_2,
//char V_3,
//object[] V_4,
//object[] V_5)
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.1
//IL_0049: brtrue.s IL_0056
//IL_004b: ldstr "value"
//IL_0050: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_0055: throw
//IL_0056: ldarg.2
//IL_0057: brtrue.s IL_0064
//IL_0059: ldstr "format"
//IL_005e: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_0063: throw
//IL_0064: ldarg.1
//IL_0065: callvirt instance class System.Type System.Object::GetType()
//IL_006a: stloc.0
//IL_006b: ldloc.0
//IL_006c: isinst System.RuntimeType
//IL_0071: brtrue.s IL_0088
//IL_0073: ldstr "Arg_MustBeType"
//IL_0078: call string System.Environment::GetResourceString(string)
//IL_007d: ldstr "valueType"
//IL_0082: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0087: throw
//IL_0088: ldarg.0
//IL_0089: call class System.Type System.Enum::GetUnderlyingType(class System.Type)
//IL_008e: stloc.1
//IL_008f: ldloc.0
//IL_0090: callvirt instance bool System.Type::get_IsEnum()
//IL_0095: brfalse.s IL_00eb
//IL_0097: ldloc.0
//IL_0098: call class System.Type System.Enum::GetUnderlyingType(class System.Type)
//IL_009d: stloc.2
//IL_009e: ldloc.0
//IL_009f: ldarg.0
//IL_00a0: beq.s IL_00da
//IL_00a2: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_00a7: ldstr "Arg_EnumAndObjectMustBeSameType"
//IL_00ac: call string System.Environment::GetResourceString(string)
//IL_00b1: ldc.i4.2
//IL_00b2: newarr System.Object
//IL_00b7: stloc.s V_4
//IL_00b9: ldloc.s V_4
//IL_00bb: ldc.i4.0
//IL_00bc: ldloc.0
//IL_00bd: callvirt instance string System.Object::ToString()
//IL_00c2: stelem.ref
//IL_00c3: ldloc.s V_4
//IL_00c5: ldc.i4.1
//IL_00c6: ldarg.0
//IL_00c7: callvirt instance string System.Object::ToString()
//IL_00cc: stelem.ref
//IL_00cd: ldloc.s V_4
//IL_00cf: call string System.String::Format(class System.IFormatProvider,
//string,
//object[])
//IL_00d4: newobj instance void System.ArgumentException::.ctor(string)
//IL_00d9: throw
//IL_00da: ldloc.2
//IL_00db: stloc.0
//IL_00dc: ldarg.1
//IL_00dd: castclass System.Enum
//IL_00e2: callvirt instance object System.Enum::GetValue()
//IL_00e7: starg.s 'value'
//IL_00e9: br.s IL_0127
//IL_00eb: ldloc.0
//IL_00ec: ldloc.1
//IL_00ed: beq.s IL_0127
//IL_00ef: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_00f4: ldstr "Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType"
//IL_00f9: call string System.Environment::GetResourceString(string)
//IL_00fe: ldc.i4.2
//IL_00ff: newarr System.Object
//IL_0104: stloc.s V_5
//IL_0106: ldloc.s V_5
//IL_0108: ldc.i4.0
//IL_0109: ldloc.0
//IL_010a: callvirt instance string System.Object::ToString()
//IL_010f: stelem.ref
//IL_0110: ldloc.s V_5
//IL_0112: ldc.i4.1
//IL_0113: ldloc.1
//IL_0114: callvirt instance string System.Object::ToString()
//IL_0119: stelem.ref
//IL_011a: ldloc.s V_5
//IL_011c: call string System.String::Format(class System.IFormatProvider,
//string,
//object[])
//IL_0121: newobj instance void System.ArgumentException::.ctor(string)
//IL_0126: throw
//IL_0127: ldarg.2
//IL_0128: callvirt instance int32 System.String::get_Length()
//IL_012d: ldc.i4.1
//IL_012e: beq.s IL_0140
//IL_0130: ldstr "Format_InvalidEnumFormatSpecification"
//IL_0135: call string System.Environment::GetResourceString(string)
//IL_013a: newobj instance void System.FormatException::.ctor(string)
//IL_013f: throw
//IL_0140: ldarg.2
//IL_0141: ldc.i4.0
//IL_0142: callvirt instance char System.String::get_Chars(int32)
//IL_0147: stloc.3
//IL_0148: ldloc.3
//IL_0149: ldc.i4.s 68
//IL_014b: beq.s IL_0152
//IL_014d: ldloc.3
//IL_014e: ldc.i4.s 100
//IL_0150: bne.un.s IL_0159
//IL_0152: ldarg.1
//IL_0153: callvirt instance string System.Object::ToString()
//IL_0158: ret
//IL_0159: ldloc.3
//IL_015a: ldc.i4.s 88
//IL_015c: beq.s IL_0163
//IL_015e: ldloc.3
//IL_015f: ldc.i4.s 120
//IL_0161: bne.un.s IL_016a
//IL_0163: ldarg.1
//IL_0164: call string System.Enum::InternalFormattedHexString(object)
//IL_0169: ret
//IL_016a: ldloc.3
//IL_016b: ldc.i4.s 71
//IL_016d: beq.s IL_0174
//IL_016f: ldloc.3
//IL_0170: ldc.i4.s 103
//IL_0172: bne.un.s IL_017c
//IL_0174: ldarg.0
//IL_0175: ldarg.1
//IL_0176: call string System.Enum::InternalFormat(class System.Type,
//object)
//IL_017b: ret
//IL_017c: ldloc.3
//IL_017d: ldc.i4.s 70
//IL_017f: beq.s IL_0186
//IL_0181: ldloc.3
//IL_0182: ldc.i4.s 102
//IL_0184: bne.un.s IL_018e
//IL_0186: ldarg.0
//IL_0187: ldarg.1
//IL_0188: call string System.Enum::InternalFlagsFormat(class System.Type,
//object)
//IL_018d: ret
//IL_018e: ldstr "Format_InvalidEnumFormatSpecification"
//IL_0193: call string System.Environment::GetResourceString(string)
//IL_0198: newobj instance void System.FormatException::.ctor(string)
//IL_019d: throw
System.Type V_0, V_1, V_2;
char V_3;
object[] V_4, V_5;
if(enumType==null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if(enumType as System.Runtimetype==null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"),"enumType");
}
else
{
//IL_002b
if(enumType.IsEnum)
{
//IL_0048
if(@value==null)
{
throw new System.ArgumentNullException("value");
}
else
{
if(format==null)
{
throw new System.ArgumentNullException("format");
}
else
{
//IL_0064
V_0=@value.GetType();
if(V_0 as System.RuntimeType==null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"),"valueType");
}
else
{
//IL_0088
V_1=System.Enum.GetUnderlyingType(enumType);
if(V_0.IsEnum)
{
V_2=System.Enum.GetUnderlyingType(V_0);
if(V_0==enumType)
{
//IL_00da
V_0 = V_2;
@value = ((System.Enum)@value).GetValue();
//直接跳往IL_0127
if(format.Length==1)
{
//IL_0140
V_3=format[0];
if(V_3=='D'||V_3=='d')
{
return @value.ToString();
}
else
{
//IL_0159
if (V_3 == 'X' || V_3 == 'x')
{
return System.Enum.InternalFormattedHexString(@value);
}
else if (V_3 == 'G' || V_3 == 'g')
{
return System.Enum.InternalFormat(enumType, @value);
}
else if (V_3 == 'F' || V_3 == 'f')
{
return System.Enum.InternalFlagsFormat(enumType, @value);
}
else
{
throw new System.FormatException(System.Environment.GetResourceString("Format_InvalidEnumFormatSpecification"));
}
}
}
else
{
throw new System.FormatException(System.Environment.GetResourceString("Format_InvalidEnumFormatSpecification"));
}
}
else
{
//IL_00a2
V_4 = new object[2];
V_4[0] = V_0.ToString();
V_4[1] = enumType.ToString();
throw new System.ArgumentException(string.Format(CultureInfo.CurrentCulture, System.Environment.GetResourceString("Arg_EnumAndObjectMustBeSameType"), V_4));
}
}
else
{
//IL_00eb
if(V_0==V_1)
{
//IL_0127
if (format.Length == 1)
{
//IL_0140
V_3 = format[0];
if (V_3 == 'D' || V_3 == 'd')
{
return @value.ToString();
}
else
{
//IL_0159
if (V_3 == 'X' || V_3 == 'x')
{
return System.Enum.InternalFormattedHexString(@value);
}
else if (V_3 == 'G' || V_3 == 'g')
{
return System.Enum.InternalFormat(enumType, @value);
}
else if (V_3 == 'F' || V_3 == 'f')
{
return System.Enum.InternalFlagsFormat(enumType, @value);
}
else
{
throw new System.FormatException(System.Environment.GetResourceString("Format_InvalidEnumFormatSpecification"));
}
}
}
else
{
throw new System.FormatException(System.Environment.GetResourceString("Format_InvalidEnumFormatSpecification"));
}
}
else
{
V_5=new object[2];
V_5[0]=V_0.ToString();
V_5[1]=V_1.ToString();
throw new System.ArgumentException(string.Format(CultureInfo.CurrentCulture,System.Environment.GetResourceString("Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType"),V_5));
}
}
}
}
}
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
private object GetValue()
{
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::InternalGetValue()
//IL_0006: ret
return this.InternalGetValue();
}
private string ToHexString()
{
//.maxstack 3
//.locals init (class System.Type V_0,
//class System.Reflection.FieldInfo V_1)
//IL_0000: ldarg.0
//IL_0001: call instance class System.Type System.Object::GetType()
//IL_0006: stloc.0
//IL_0007: ldloc.0
//IL_0008: call class System.Reflection.FieldInfo System.Enum::GetValueField(class System.Type)
//IL_000d: stloc.1
//IL_000e: ldloc.1
//IL_000f: castclass System.Reflection.RtFieldInfo
//IL_0014: ldarg.0
//IL_0015: ldc.i4.0
//IL_0016: callvirt instance object System.Reflection.RtFieldInfo::InternalGetValue(object,
//bool)
//IL_001b: call string System.Enum::InternalFormattedHexString(object)
//IL_0020: ret
System.Type V_0;
System.Reflection.FieldInfo V_1;
V_0=this.GetType();
V_1=System.Enum.GetValueField(V_0);
return System.Enum.InternalFormattedHexString(((System.Reflection.RtFieldInfo)V_1).InternalGetValue(this, false));
}
[MethodImpl(MethodImplAttributes.InternalCall)]
private object InternalGetValue()
{
//internalcall
}
[MethodImpl(MethodImplAttributes.InternalCall)]
public virtual bool Equals(object obj)
{
//internalcall
}
public override int GetHashCode()
{
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: callvirt instance int32 System.Object::GetHashCode()
//IL_000b: ret
return this.GetValue().GetHashCode();
}
public override string ToString()
{
//.maxstack 3
//.locals init (class System.Type V_0,
//class System.Reflection.FieldInfo V_1,
//object V_2)
//IL_0000: ldarg.0
//IL_0001: call instance class System.Type System.Object::GetType()
//IL_0006: stloc.0
//IL_0007: ldloc.0
//IL_0008: call class System.Reflection.FieldInfo System.Enum::GetValueField(class System.Type)
//IL_000d: stloc.1
//IL_000e: ldloc.1
//IL_000f: castclass System.Reflection.RtFieldInfo
//IL_0014: ldarg.0
//IL_0015: ldc.i4.0
//IL_0016: callvirt instance object System.Reflection.RtFieldInfo::InternalGetValue(object,
//bool)
//IL_001b: stloc.2
//IL_001c: ldloc.0
//IL_001d: ldloc.2
//IL_001e: call string System.Enum::InternalFormat(class System.Type,
//object)
//IL_0023: ret
System.Type V_0;
System.Reflection.FieldInfo V_1;
object V_2;
V_0=this.GetType();
V_1=System.Enum.GetValueField(V_0);
V_2=((System.Reflection.RtFieldInfo)V_1).InternalGetValue(this, false);
return System.Enum.InternalFormat(V_0,V_2);
}
public new virtual sealed string ToString(string format, System.IFormatProvider provider)
{
//System.ObsoleteAttribute("The provider argument is not used. Please use ToString(String).")
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: ldarg.1
//IL_0002: call instance string System.Enum::ToString(string)
//IL_0007: ret
return this.ToString(format);
}
public new virtual sealed int CompareTo(object target)
{
//.maxstack 5
//.locals init (int32 V_0,
//class System.Type V_1,
//class System.Type V_2,
//object[] V_3)
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_0009
//IL_0003: newobj instance void System.NullReferenceException::.ctor()
//IL_0008: throw
//IL_0009: ldarg.0
//IL_000a: ldarg.1
//IL_000b: call int32 System.Enum::InternalCompareTo(object,
//object)
//IL_0010: stloc.0
//IL_0011: ldloc.0
//IL_0012: ldc.i4.2
//IL_0013: bge.s IL_0017
//IL_0015: ldloc.0
//IL_0016: ret
//IL_0017: ldloc.0
//IL_0018: ldc.i4.2
//IL_0019: bne.un.s IL_005d
//IL_001b: ldarg.0
//IL_001c: call instance class System.Type System.Object::GetType()
//IL_0021: stloc.1
//IL_0022: ldarg.1
//IL_0023: callvirt instance class System.Type System.Object::GetType()
//IL_0028: stloc.2
//IL_0029: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_002e: ldstr "Arg_EnumAndObjectMustBeSameType"
//IL_0033: call string System.Environment::GetResourceString(string)
//IL_0038: ldc.i4.2
//IL_0039: newarr System.Object
//IL_003e: stloc.3
//IL_003f: ldloc.3
//IL_0040: ldc.i4.0
//IL_0041: ldloc.2
//IL_0042: callvirt instance string System.Object::ToString()
//IL_0047: stelem.ref
//IL_0048: ldloc.3
//IL_0049: ldc.i4.1
//IL_004a: ldloc.1
//IL_004b: callvirt instance string System.Object::ToString()
//IL_0050: stelem.ref
//IL_0051: ldloc.3
//IL_0052: call string System.String::Format(class System.IFormatProvider,
//string,
//object[])
//IL_0057: newobj instance void System.ArgumentException::.ctor(string)
//IL_005c: throw
//IL_005d: ldstr "InvalidOperation_UnknownEnumType"
//IL_0062: call string System.Environment::GetResourceString(string)
//IL_0067: newobj instance void System.InvalidOperationException::.ctor(string)
//IL_006c: throw
int V_0;
System.Type V_1, V_2;
object[] V_3;
if(this==null)
{
throw new System.NullReferenceException();
}
else
{
V_0=System.Enum.InternalCompareTo(this,target);
if(V_0>=2)
{
//IL_0017
if(V_0==2)
{
V_1=this.GetType();
V_2=target.GetType();
V_3=new object[2];
V_3[0]=V_2.ToString();
V_3[1]=V_1.ToString();
throw new System.ArgumentException(string.Format(CultureInfo.CurrentCulture,System.Environment.GetResourceString("Arg_EnumAndObjectMustBeSameType"),V_3));}
else
{
//IL_005d
throw new System.InvalidOperationException(System.Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
}
}
else
{
return V_0;
}
}
}
public string ToString(string format)
{
//.maxstack 3
//IL_0000: ldarg.1
//IL_0001: brfalse.s IL_000b
//IL_0003: ldarg.1
//IL_0004: callvirt instance int32 System.String::get_Length()
//IL_0009: brtrue.s IL_0012
//IL_000b: ldstr "G"
//IL_0010: starg.s format
//IL_0012: ldarg.1
//IL_0013: ldstr "G"
//IL_0018: ldc.i4.5
//IL_0019: call int32 System.String::Compare(string,
//string,
//valuetype System.StringComparison)
//IL_001e: brtrue.s IL_0027
//IL_0020: ldarg.0
//IL_0021: callvirt instance string System.Object::ToString()
//IL_0026: ret
//IL_0027: ldarg.1
//IL_0028: ldstr "D"
//IL_002d: ldc.i4.5
//IL_002e: call int32 System.String::Compare(string,
//string,
//valuetype System.StringComparison)
//IL_0033: brtrue.s IL_0041
//IL_0035: ldarg.0
//IL_0036: call instance object System.Enum::GetValue()
//IL_003b: callvirt instance string System.Object::ToString()
//IL_0040: ret
//IL_0041: ldarg.1
//IL_0042: ldstr "X"
//IL_0047: ldc.i4.5
//IL_0048: call int32 System.String::Compare(string,
//string,
//valuetype System.StringComparison)
//IL_004d: brtrue.s IL_0056
//IL_004f: ldarg.0
//IL_0050: call instance string System.Enum::ToHexString()
//IL_0055: ret
//IL_0056: ldarg.1
//IL_0057: ldstr "F"
//IL_005c: ldc.i4.5
//IL_005d: call int32 System.String::Compare(string,
//string,
//valuetype System.StringComparison)
//IL_0062: brtrue.s IL_0076
//IL_0064: ldarg.0
//IL_0065: call instance class System.Type System.Object::GetType()
//IL_006a: ldarg.0
//IL_006b: call instance object System.Enum::GetValue()
//IL_0070: call string System.Enum::InternalFlagsFormat(class System.Type,
//object)
//IL_0075: ret
//IL_0076: ldstr "Format_InvalidEnumFormatSpecification"
//IL_007b: call string System.Environment::GetResourceString(string)
//IL_0080: newobj instance void System.FormatException::.ctor(string)
//IL_0085: throw
if(format==null||format.Length==0)
{
format="G";
}
else
{
if(string.Compare(format,"G",System.StringComparison.OrdinalIgnoreCase)==0)
{
return this.ToString();
}
else if (string.Compare(format, "D", System.StringComparison.OrdinalIgnoreCase) == 0)
{
return this.GetValue().ToString();
}
else if (string.Compare(format, "X", System.StringComparison.OrdinalIgnoreCase) == 0)
{
return this.ToHexString();
}
else if (string.Compare(format, "F", System.StringComparison.OrdinalIgnoreCase) == 0)
{
return System.Enum.InternalFlagsFormat(this.GetType(), this.GetValue());
}
else
{
throw new System.FormatException(System.Environment.GetResourceString("Format_InvalidEnumFormatSpecification"));
}
}
}
[Obsolete("The provider argument is not used. Please use ToString().")]
public new virtual sealed string ToString( System.IFormatProvider provider)
{
//System.ObsoleteAttribute("The provider argument is not used. Please use ToString().")
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: callvirt instance string System.Object::ToString()
//IL_0006: ret
return this.ToString();
}
public new virtual sealed System.TypeCode GetTypeCode()
{
//.maxstack 2
//.locals init (class System.Type V_0,
//class System.Type V_1)
//IL_0000: ldarg.0
//IL_0001: call instance class System.Type System.Object::GetType()
//IL_0006: stloc.0
//IL_0007: ldloc.0
//IL_0008: call class System.Type System.Enum::GetUnderlyingType(class System.Type)
//IL_000d: stloc.1
//IL_000e: ldloc.1
//IL_000f: ldtoken System.Int32
//IL_0014: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0019: bne.un.s IL_001e
//IL_001b: ldc.i4.s 9
//IL_001d: ret
//IL_001e: ldloc.1
//IL_001f: ldtoken System.SByte
//IL_0024: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0029: bne.un.s IL_002d
//IL_002b: ldc.i4.5
//IL_002c: ret
//IL_002d: ldloc.1
//IL_002e: ldtoken System.Int16
//IL_0033: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0038: bne.un.s IL_003c
//IL_003a: ldc.i4.7
//IL_003b: ret
//IL_003c: ldloc.1
//IL_003d: ldtoken System.Int64
//IL_0042: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0047: bne.un.s IL_004c
//IL_0049: ldc.i4.s 11
//IL_004b: ret
//IL_004c: ldloc.1
//IL_004d: ldtoken System.UInt32
//IL_0052: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0057: bne.un.s IL_005c
//IL_0059: ldc.i4.s 10
//IL_005b: ret
//IL_005c: ldloc.1
//IL_005d: ldtoken System.Byte
//IL_0062: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0067: bne.un.s IL_006b
//IL_0069: ldc.i4.6
//IL_006a: ret
//IL_006b: ldloc.1
//IL_006c: ldtoken System.UInt16
//IL_0071: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0076: bne.un.s IL_007a
//IL_0078: ldc.i4.8
//IL_0079: ret
//IL_007a: ldloc.1
//IL_007b: ldtoken System.UInt64
//IL_0080: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_0085: bne.un.s IL_008a
//IL_0087: ldc.i4.s 12
//IL_0089: ret
//IL_008a: ldstr "InvalidOperation_UnknownEnumType"
//IL_008f: call string System.Environment::GetResourceString(string)
//IL_0094: newobj instance void System.InvalidOperationException::.ctor(string)
//IL_0099: throw
System.Type V_0, V_1;
V_0 = this.GetType();
V_1 = System.Enum.GetUnderlyingType(V_0);
if (V_1 == typeof(int))
{
return TypeCode.Int32;
}
else if (V_1 == typeof(sbyte))
{
return TypeCode.SByte;
}
else if (V_1 == typeof(short))
{
return TypeCode.Int16;
}
else if (V_1 == typeof(long))
{
return TypeCode.Int64;
}
else if (V_1 == typeof(uint))
{
return TypeCode.UInt32;
}
else if (V_1 == typeof(byte))
{
return TypeCode.Byte;
}
else if (V_1 == typeof(ushort))
{
return TypeCode.UInt16;
}
else if (V_1 == typeof(ulong))
{
return TypeCode.UInt64;
}
else
{
throw new System.InvalidOperationException(System.Environment.GetResourceString("InvalidOperation_UnknownEnumType"));
}
}
private new virtual sealed bool System.IConvertible.ToBoolean( System.IFormatProvider provider)
{
//.override System.IConvertible::ToBoolean
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call bool System.Convert::ToBoolean(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToBoolean(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed char System.IConvertible.ToChar( System.IFormatProvider provider)
{
//.override System.IConvertible::ToChar
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call char System.Convert::ToChar(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToChar(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed sbyte System.IConvertible.ToSByte( System.IFormatProvider provider)
{
//.override System.IConvertible::ToSByte
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call int8 System.Convert::ToSByte(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToSByte(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed byte System.IConvertible.ToByte( System.IFormatProvider provider)
{
//.override System.IConvertible::ToByte
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call uint8 System.Convert::ToByte(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToByte(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed short System.IConvertible.ToInt16( System.IFormatProvider provider)
{
//.override System.IConvertible::ToInt16
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call int16 System.Convert::ToInt16(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToInt16(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed ushort System.IConvertible.ToUInt16( System.IFormatProvider provider)
{
//.override System.IConvertible::ToUInt16
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call uint16 System.Convert::ToUInt16(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToUInt16(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed int System.IConvertible.ToInt32( System.IFormatProvider provider)
{
//.override System.IConvertible::ToInt32
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call int32 System.Convert::ToInt32(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToInt32(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed uint System.IConvertible.ToUInt32( System.IFormatProvider provider)
{
//.override System.IConvertible::ToUInt32
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call uint32 System.Convert::ToUInt32(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToUInt32(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed long System.IConvertible.ToInt64( System.IFormatProvider provider)
{
//.override System.IConvertible::ToInt64
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call int64 System.Convert::ToInt64(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToInt64(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed ulong System.IConvertible.ToUInt64( System.IFormatProvider provider)
{
//.override System.IConvertible::ToUInt64
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call uint64 System.Convert::ToUInt64(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToUInt64(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed float System.IConvertible.ToSingle( System.IFormatProvider provider)
{
//.override System.IConvertible::ToSingle
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call float32 System.Convert::ToSingle(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToSingle(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed double System.IConvertible.ToDouble( System.IFormatProvider provider)
{
//.override System.IConvertible::ToDouble
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call float64 System.Convert::ToDouble(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToDouble(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed System.Decimal System.IConvertible.ToDecimal( System.IFormatProvider provider)
{
//.override System.IConvertible::ToDecimal
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance object System.Enum::GetValue()
//IL_0006: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_000b: call valuetype System.Decimal System.Convert::ToDecimal(object,
//class System.IFormatProvider)
//IL_0010: ret
System.Convert.ToDecimal(this.GetValue(), CultureInfo.CurrentCulture);
}
private new virtual sealed System.DateTime System.IConvertible.ToDateTime( System.IFormatProvider provider)
{
//.override System.IConvertible::ToDateTime
//.maxstack 5
//.locals init (object[] V_0)
//IL_0000: call class System.Globalization.CultureInfo System.Globalization.CultureInfo::get_CurrentCulture()
//IL_0005: ldstr "InvalidCast_FromTo"
//IL_000a: call string System.Environment::GetResourceString(string)
//IL_000f: ldc.i4.2
//IL_0010: newarr System.Object
//IL_0015: stloc.0
//IL_0016: ldloc.0
//IL_0017: ldc.i4.0
//IL_0018: ldstr "Enum"
//IL_001d: stelem.ref
//IL_001e: ldloc.0
//IL_001f: ldc.i4.1
//IL_0020: ldstr "DateTime"
//IL_0025: stelem.ref
//IL_0026: ldloc.0
//IL_0027: call string System.String::Format(class System.IFormatProvider,
//string,
//object[])
//IL_002c: newobj instance void System.InvalidCastException::.ctor(string)
//IL_0031: throw
object[] V_0;
V_0 = new object[2];
V_0[0] = "Enum";
V_0[1] = "DateTime";
throw new System.InvalidCastException(string.Format(CultureInfo.CurrentCulture, System.Environment.GetResourceString("InvalidCast_FromTo"), V_0));
}
private new virtual sealed object System.IConvertible.ToType( System.Type @type, System.IFormatProvider provider)
{
//.override System.IConvertible::ToType
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: ldarg.1
//IL_0002: ldarg.2
//IL_0003: call object System.Convert::DefaultToType(class System.IConvertible,
//class System.Type,
//class System.IFormatProvider)
//IL_0008: ret
return System.Convert.DefaultToType((System.IConvertible)this, @type, provider);
}
[CLSCompliant(false)]
public static object ToObject( System.Type enumType, sbyte @value)
{
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: ldarg.1
//IL_004a: conv.i8
//IL_004b: call object System.Enum::InternalBoxEnum(class System.Type,
//int64)
//IL_0050: ret
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
if (enumType.IsEnum)
{
return System.Enum.InternalBoxEnum(enumType, (long)@value);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
[ComVisible(true)]
public static object ToObject( System.Type enumType, short @value)
{
//System.Runtime.InteropServices.ComVisibleAttribute(true)
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: ldarg.1
//IL_004a: conv.i8
//IL_004b: call object System.Enum::InternalBoxEnum(class System.Type,
//int64)
//IL_0050: ret
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
if (enumType.IsEnum)
{
return System.Enum.InternalBoxEnum(enumType,(long)@value);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
public static object ToObject( System.Type enumType, int @value)
{
//System.Runtime.InteropServices.ComVisibleAttribute(true)
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: ldarg.1
//IL_004a: conv.i8
//IL_004b: call object System.Enum::InternalBoxEnum(class System.Type,
//int64)
//IL_0050: ret
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
if (enumType.IsEnum)
{
return System.Enum.InternalBoxEnum(enumType, (long)@value);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
public static object ToObject( System.Type enumType, byte @value)
{
//System.Runtime.InteropServices.ComVisibleAttribute(true)
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: ldarg.1
//IL_004a: conv.u8
//IL_004b: call object System.Enum::InternalBoxEnum(class System.Type,
//int64)
//IL_0050: ret
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
if (enumType.IsEnum)
{
return System.Enum.InternalBoxEnum(enumType, (long)(ulong)@value);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
public static object ToObject( System.Type enumType, ushort @value)
{
//System.Runtime.InteropServices.ComVisibleAttribute(true)
//System.CLSCompliantAttribute(false)
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: ldarg.1
//IL_004a: conv.u8
//IL_004b: call object System.Enum::InternalBoxEnum(class System.Type,
//int64)
//IL_0050: ret
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
if (enumType.IsEnum)
{
return System.Enum.InternalBoxEnum(enumType, (long)(ulong)@value);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
public static object ToObject( System.Type enumType, uint @value)
{
//System.Runtime.InteropServices.ComVisibleAttribute(true)
//System.CLSCompliantAttribute(false)
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: ldarg.1
//IL_004a: conv.u8
//IL_004b: call object System.Enum::InternalBoxEnum(class System.Type,
//int64)
//IL_0050: ret
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
if (enumType.IsEnum)
{
return System.Enum.InternalBoxEnum(enumType, (long)(ulong)@value);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
public static object ToObject( System.Type enumType, long @value)
{
//System.Runtime.InteropServices.ComVisibleAttribute(true)
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: ldarg.1
//IL_004a: call object System.Enum::InternalBoxEnum(class System.Type,
//int64)
//IL_004f: ret
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
if (enumType.IsEnum)
{
return System.Enum.InternalBoxEnum(enumType, (long)@value);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
public static object ToObject( System.Type enumType, ulong @value)
{
//System.Runtime.InteropServices.ComVisibleAttribute(true)
//System.CLSCompliantAttribute(false)
//.maxstack 3
//IL_0000: ldarg.0
//IL_0001: brtrue.s IL_000e
//IL_0003: ldstr "enumType"
//IL_0008: newobj instance void System.ArgumentNullException::.ctor(string)
//IL_000d: throw
//IL_000e: ldarg.0
//IL_000f: isinst System.RuntimeType
//IL_0014: brtrue.s IL_002b
//IL_0016: ldstr "Arg_MustBeType"
//IL_001b: call string System.Environment::GetResourceString(string)
//IL_0020: ldstr "enumType"
//IL_0025: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_002a: throw
//IL_002b: ldarg.0
//IL_002c: callvirt instance bool System.Type::get_IsEnum()
//IL_0031: brtrue.s IL_0048
//IL_0033: ldstr "Arg_MustBeEnum"
//IL_0038: call string System.Environment::GetResourceString(string)
//IL_003d: ldstr "enumType"
//IL_0042: newobj instance void System.ArgumentException::.ctor(string,
//string)
//IL_0047: throw
//IL_0048: ldarg.0
//IL_0049: ldarg.1
//IL_004a: call object System.Enum::InternalBoxEnum(class System.Type,
//int64)
//IL_004f: ret
if (enumType == null)
{
throw new System.ArgumentNullException("enumType");
}
else
{
if (enumType as System.RuntimeType == null)
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeType"), "enumType");
}
else
{
if (enumType.IsEnum)
{
return System.Enum.InternalBoxEnum(enumType, (long)@value);
}
else
{
throw new System.ArgumentException(System.Environment.GetResourceString("Arg_MustBeEnum"), "enumType");
}
}
}
}
protected Enum():base()
{
//.maxstack 8
//IL_0000: ldarg.0
//IL_0001: call instance void System.ValueType::.ctor()
//IL_0006: ret
}
private static Enum()
{
//.maxstack 3
//.locals init (char[] V_0)
//IL_0000: ldc.i4.1
//IL_0001: newarr System.Char
//IL_0006: stloc.0
//IL_0007: ldloc.0
//IL_0008: ldc.i4.0
//IL_0009: ldc.i4.s 44
//IL_000b: stelem.i2
//IL_000c: ldloc.0
//IL_000d: stsfld char[] System.Enum::enumSeperatorCharArray
//IL_0012: ldtoken System.Int32
//IL_0017: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_001c: stsfld class System.Type System.Enum::intType
//IL_0021: ldtoken System.String
//IL_0026: call class System.Type System.Type::GetTypeFromHandle(valuetype System.RuntimeTypeHandle)
//IL_002b: stsfld class System.Type System.Enum::stringType
//IL_0030: newobj instance void System.Collections.Hashtable::.ctor()
//IL_0035: call class System.Collections.Hashtable System.Collections.Hashtable::Synchronized(class System.Collections.Hashtable)
//IL_003a: stsfld class System.Collections.Hashtable System.Enum::fieldInfoHash
//IL_003f: ret
char[] V_0;
V_0 = new char[1];
V_0=',';
System.Enum.enumSeperatorCharArray = V_0;
System.Enum.intType = typeof(int);
System.Enum.stringType = typeof(string);
System.Enum.fieldInfoHash=System.Collections.Hashtable.Synchronized((new System.Collections.Hashtable()));
}
}
}