Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetEnumName()

virtual ? string System.Type.GetEnumName ( object value)
inlinevirtualinherited

Reimplemented in System.Reflection.SignatureType, and System.RuntimeType.

Definition at line 1189 of file Type.cs.

1190 {
1191 if (value == null)
1192 {
1193 throw new ArgumentNullException("value");
1194 }
1195 if (!IsEnum)
1196 {
1197 throw new ArgumentException(SR.Arg_MustBeEnum, "value");
1198 }
1199 Type type = value.GetType();
1200 if (!type.IsEnum && !IsIntegerType(type))
1201 {
1202 throw new ArgumentException(SR.Arg_MustBeEnumBaseTypeOrEnum, "value");
1203 }
1204 Array enumRawConstantValues = GetEnumRawConstantValues();
1205 int num = BinarySearch(enumRawConstantValues, value);
1206 if (num >= 0)
1207 {
1208 string[] enumNames = GetEnumNames();
1209 return enumNames[num];
1210 }
1211 return null;
1212 }
Array GetEnumRawConstantValues()
Definition Type.cs:1224
virtual string[] GetEnumNames()
Definition Type.cs:1214
virtual bool IsEnum
Definition Type.cs:227
static int BinarySearch(Array array, object value)
Definition Type.cs:1269
static bool IsIntegerType(Type t)
Definition Type.cs:1280

References System.SR.Arg_MustBeEnum, System.SR.Arg_MustBeEnumBaseTypeOrEnum, System.Type.BinarySearch(), System.Type.GetEnumNames(), System.Type.GetEnumRawConstantValues(), System.Type.GetType(), System.Type.IsEnum, System.Type.IsIntegerType(), System.type, and System.value.

Referenced by System.Enum.GetName().