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

◆ IsEnumDefined()

virtual bool System.Type.IsEnumDefined ( object value)
inlinevirtualinherited

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

Definition at line 1147 of file Type.cs.

1148 {
1149 if (value == null)
1150 {
1151 throw new ArgumentNullException("value");
1152 }
1153 if (!IsEnum)
1154 {
1155 throw new ArgumentException(SR.Arg_MustBeEnum, "value");
1156 }
1157 Type type = value.GetType();
1158 if (type.IsEnum)
1159 {
1160 if (!type.IsEquivalentTo(this))
1161 {
1162 throw new ArgumentException(SR.Format(SR.Arg_EnumAndObjectMustBeSameType, type, this));
1163 }
1164 type = type.GetEnumUnderlyingType();
1165 }
1166 if (type == typeof(string))
1167 {
1168 string[] enumNames = GetEnumNames();
1169 object[] array = enumNames;
1170 if (Array.IndexOf(array, value) >= 0)
1171 {
1172 return true;
1173 }
1174 return false;
1175 }
1176 if (IsIntegerType(type))
1177 {
1178 Type enumUnderlyingType = GetEnumUnderlyingType();
1179 if (enumUnderlyingType.GetTypeCodeImpl() != type.GetTypeCodeImpl())
1180 {
1181 throw new ArgumentException(SR.Format(SR.Arg_EnumUnderlyingTypeAndObjectMustBeSameType, type, enumUnderlyingType));
1182 }
1183 Array enumRawConstantValues = GetEnumRawConstantValues();
1184 return BinarySearch(enumRawConstantValues, value) >= 0;
1185 }
1186 throw new InvalidOperationException(SR.InvalidOperation_UnknownEnumType);
1187 }
Array GetEnumRawConstantValues()
Definition Type.cs:1224
virtual string[] GetEnumNames()
Definition Type.cs:1214
virtual bool IsEnum
Definition Type.cs:227
virtual Type GetEnumUnderlyingType()
Definition Type.cs:1035
static int BinarySearch(Array array, object value)
Definition Type.cs:1269
static bool IsIntegerType(Type t)
Definition Type.cs:1280

References System.SR.Arg_EnumAndObjectMustBeSameType, System.SR.Arg_EnumUnderlyingTypeAndObjectMustBeSameType, System.SR.Arg_MustBeEnum, System.array, System.Type.BinarySearch(), System.SR.Format(), System.Type.GetEnumNames(), System.Type.GetEnumRawConstantValues(), System.Type.GetEnumUnderlyingType(), System.Type.GetType(), System.Type.GetTypeCodeImpl(), System.Array.IndexOf(), System.SR.InvalidOperation_UnknownEnumType, System.Type.IsEnum, System.Type.IsIntegerType(), System.type, and System.value.

Referenced by System.Enum.IsDefined().