12[TypeForwardedFrom(
"mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")]
37 public override extern bool Equals([NotNullWhen(
true)]
object?
obj);
54 if (enumInfo ==
null || (getNames && enumInfo.
Names ==
null))
68 ref
byte rawData = ref this.GetRawData();
71 CorElementType.ELEMENT_TYPE_I1 =>
Unsafe.As<byte, sbyte>(ref rawData).
ToString(),
72 CorElementType.ELEMENT_TYPE_U1 => rawData.ToString(),
73 CorElementType.ELEMENT_TYPE_BOOLEAN =>
Unsafe.As<byte,
bool>(ref rawData).
ToString(),
74 CorElementType.ELEMENT_TYPE_I2 =>
Unsafe.As<byte,
short>(ref rawData).
ToString(),
75 CorElementType.ELEMENT_TYPE_U2 =>
Unsafe.As<byte, ushort>(ref rawData).
ToString(),
76 CorElementType.ELEMENT_TYPE_CHAR =>
Unsafe.As<byte,
char>(ref rawData).
ToString(),
77 CorElementType.ELEMENT_TYPE_I4 =>
Unsafe.As<byte,
int>(ref rawData).
ToString(),
78 CorElementType.ELEMENT_TYPE_U4 =>
Unsafe.As<byte, uint>(ref rawData).
ToString(),
79 CorElementType.ELEMENT_TYPE_R4 =>
Unsafe.As<byte,
float>(ref rawData).
ToString(),
80 CorElementType.ELEMENT_TYPE_I8 =>
Unsafe.As<byte,
long>(ref rawData).
ToString(),
81 CorElementType.ELEMENT_TYPE_U8 =>
Unsafe.As<byte, ulong>(ref rawData).
ToString(),
82 CorElementType.ELEMENT_TYPE_R8 =>
Unsafe.As<byte,
double>(ref rawData).
ToString(),
91 ref
byte rawData = ref this.GetRawData();
134 TypeCode.Byte => ((byte)
value).ToString(
"X2",
null),
135 TypeCode.Boolean => ((
bool)
value) ?
"01" :
"00",
136 TypeCode.Int16 => ((ushort)(
short)
value).
ToString(
"X4",
null),
137 TypeCode.UInt16 => ((ushort)
value).ToString(
"X4",
null),
139 TypeCode.UInt32 => ((uint)
value).ToString(
"X8",
null),
141 TypeCode.UInt64 => ((ulong)
value).ToString(
"X16",
null),
142 TypeCode.Int64 => ((ulong)(
long)
value).
ToString(
"X16",
null),
157 return enumInfo.
Names[num];
179 string[] names = enumInfo.
Names;
181 if (resultValue == 0
L)
191 for (num =
values.Length - 1; num >= 0; num--)
193 if (
values[num] == resultValue)
197 if (
values[num] < resultValue)
207 if (num == 0 && num4 == 0
L)
211 if ((resultValue & num4) == num4)
215 num2 = checked(num2 + names[num].Length);
219 if (resultValue != 0
L)
223 string text =
string.FastAllocateString(checked(num2 + 2 * (num3 - 1)));
225 string text2 = names[span[--num3]];
233 text2 = names[span[num3]];
244 TypeCode.SByte => (ulong)(sbyte)
value,
245 TypeCode.Byte => (byte)
value,
249 TypeCode.Char => (char)
value,
251 TypeCode.Int32 => (ulong)(
int)
value,
252 TypeCode.UInt64 => (ulong)
value,
262 TypeCode.SByte => (ulong)
Unsafe.As<TEnum, sbyte>(ref
value),
263 TypeCode.Byte =>
Unsafe.As<TEnum,
byte>(ref
value),
267 TypeCode.Char =>
Unsafe.As<TEnum,
char>(ref
value),
269 TypeCode.Int32 => (ulong)
Unsafe.As<TEnum,
int>(ref
value),
270 TypeCode.UInt64 =>
Unsafe.As<TEnum, ulong>(ref
value),
283 if ((
object)enumType ==
null)
297 if ((
object)enumType ==
null)
311 if (enumType ==
null)
320 return (TEnum[])
GetValues(typeof(TEnum));
325 if ((
object)enumType ==
null)
339 if (!GetType().IsEquivalentTo(flag.GetType()))
348 return GetEnumInfo(enumType, getNames:
false).Values;
361 if ((
object)enumType ==
null)
370 return Parse(enumType,
value, ignoreCase:
false);
375 return Parse(enumType,
value, ignoreCase:
false);
381 bool flag =
TryParse(enumType,
value, ignoreCase, throwOnFailure:
true, out result);
388 bool flag =
TryParse(enumType,
value, ignoreCase, throwOnFailure:
true, out result);
418 return TryParse(enumType,
value, ignoreCase:
false, out result);
423 return TryParse(enumType,
value, ignoreCase:
false, out result);
428 return TryParse(enumType,
value, ignoreCase, throwOnFailure:
false, out result);
433 return TryParse(enumType,
value, ignoreCase, throwOnFailure:
false, out result);
436 private static bool TryParse(
Type enumType,
string value,
bool ignoreCase,
bool throwOnFailure, out
object result)
447 return TryParse(enumType,
value.AsSpan(), ignoreCase, throwOnFailure, out result);
454 if (
value.Length == 0)
532 public static bool TryParse<TEnum>([NotNullWhen(
true)]
string?
value,
bool ignoreCase, out TEnum result) where TEnum :
struct
542 private static bool TryParse<TEnum>(
string value,
bool ignoreCase,
bool throwOnFailure, out TEnum result) where TEnum :
struct
550 result =
default(TEnum);
558 if (!typeof(TEnum).IsEnum)
563 if (
value.Length == 0)
569 result =
default(TEnum);
580 sbyte source2 = (sbyte)result3;
581 result =
Unsafe.As<sbyte, TEnum>(ref source2);
594 result =
Unsafe.As<int, TEnum>(ref result3);
600 byte source4 = (byte)result6;
601 result =
Unsafe.As<byte, TEnum>(ref source4);
607 ushort source3 = (ushort)result6;
608 result =
Unsafe.As<ushort, TEnum>(ref source3);
614 result =
Unsafe.As<uint, TEnum>(ref result6);
621 result =
Unsafe.As<long, TEnum>(ref result5);
628 result =
Unsafe.As<ulong, TEnum>(ref result4);
635 result = (flag ? ((TEnum)result2) :
default(TEnum));
649 if ((uint)(result - minInclusive) <= (uint)(maxInclusive - minInclusive))
666 result = (int)result2;
681 if (result <= maxInclusive)
698 result = (uint)result2;
726 result = (long)result2;
772 catch when (!throwOnFailure)
782 result =
ToObject(enumType, result2);
785 catch when (!throwOnFailure)
797 string[] names = enumInfo.
Names;
801 while (
value.Length > 0)
803 int num2 =
value.IndexOf(
',');
812 if (num2 ==
value.Length - 1)
823 for (
int i = 0; i < names.Length; i++)
825 if (span.EqualsOrdinalIgnoreCase(names[i]))
835 for (
int j = 0; j < names.Length; j++)
837 if (span.EqualsOrdinal(names[j]))
867 if (!
char.IsInRange(c,
'0',
'9') && c !=
'-')
910 if (!
type.IsEquivalentTo(enumType))
921 if (
type != underlyingType)
934 return value.ToString();
948 ref
byte rawData = ref this.GetRawData();
951 CorElementType.ELEMENT_TYPE_I1 =>
Unsafe.As<byte, sbyte>(ref rawData),
954 CorElementType.ELEMENT_TYPE_I2 =>
Unsafe.As<byte,
short>(ref rawData),
956 CorElementType.ELEMENT_TYPE_CHAR =>
Unsafe.As<byte,
char>(ref rawData),
958 CorElementType.ELEMENT_TYPE_U4 =>
Unsafe.As<byte, uint>(ref rawData),
960 CorElementType.ELEMENT_TYPE_I8 =>
Unsafe.As<byte,
long>(ref rawData),
962 CorElementType.ELEMENT_TYPE_R8 =>
Unsafe.As<byte,
double>(ref rawData),
964 CorElementType.ELEMENT_TYPE_U =>
Unsafe.As<byte,
UIntPtr>(ref rawData),
971 ref
byte rawData = ref this.GetRawData();
975 return (ulong)
Unsafe.As<byte, sbyte>(ref rawData);
985 return (ulong)
Unsafe.As<byte,
short>(ref rawData);
988 return Unsafe.As<byte, ushort>(ref rawData);
990 return (ulong)
Unsafe.As<byte,
int>(ref rawData);
993 return Unsafe.As<byte, uint>(ref rawData);
995 return (ulong)
Unsafe.As<byte,
long>(ref rawData);
998 return Unsafe.As<byte, ulong>(ref rawData);
1000 return (ulong)(long)
Unsafe.As<
byte,
IntPtr>(ref rawData);
1010 ref
byte rawData = ref this.GetRawData();
1013 CorElementType.ELEMENT_TYPE_I1 =>
Unsafe.As<byte, sbyte>(ref rawData).
GetHashCode(),
1014 CorElementType.ELEMENT_TYPE_U1 => rawData.GetHashCode(),
1015 CorElementType.ELEMENT_TYPE_BOOLEAN =>
Unsafe.As<byte,
bool>(ref rawData).
GetHashCode(),
1016 CorElementType.ELEMENT_TYPE_I2 =>
Unsafe.As<byte,
short>(ref rawData).
GetHashCode(),
1017 CorElementType.ELEMENT_TYPE_U2 =>
Unsafe.As<byte, ushort>(ref rawData).
GetHashCode(),
1018 CorElementType.ELEMENT_TYPE_CHAR =>
Unsafe.As<byte,
char>(ref rawData).
GetHashCode(),
1019 CorElementType.ELEMENT_TYPE_I4 =>
Unsafe.As<byte,
int>(ref rawData).
GetHashCode(),
1020 CorElementType.ELEMENT_TYPE_U4 =>
Unsafe.As<byte, uint>(ref rawData).
GetHashCode(),
1021 CorElementType.ELEMENT_TYPE_R4 =>
Unsafe.As<byte,
float>(ref rawData).
GetHashCode(),
1022 CorElementType.ELEMENT_TYPE_I8 =>
Unsafe.As<byte,
long>(ref rawData).
GetHashCode(),
1023 CorElementType.ELEMENT_TYPE_U8 =>
Unsafe.As<byte, ulong>(ref rawData).
GetHashCode(),
1024 CorElementType.ELEMENT_TYPE_R8 =>
Unsafe.As<byte,
double>(ref rawData).
GetHashCode(),
1046 if (GetType() != target.GetType())
1050 ref
byte rawData = ref this.GetRawData();
1051 ref
byte rawData2 = ref target.GetRawData();
1058 return rawData.CompareTo(rawData2);
1083 [Obsolete(
"The provider argument is not used. Use ToString(String) instead.")]
1091 if (
string.IsNullOrEmpty(
format))
1116 [Obsolete(
"The provider argument is not used. Use ToString() instead.")]
1126 CorElementType.ELEMENT_TYPE_I1 =>
TypeCode.SByte,
1127 CorElementType.ELEMENT_TYPE_U1 =>
TypeCode.Byte,
1128 CorElementType.ELEMENT_TYPE_BOOLEAN =>
TypeCode.Boolean,
1129 CorElementType.ELEMENT_TYPE_I2 =>
TypeCode.Int16,
1130 CorElementType.ELEMENT_TYPE_U2 =>
TypeCode.UInt16,
1131 CorElementType.ELEMENT_TYPE_CHAR =>
TypeCode.Char,
1132 CorElementType.ELEMENT_TYPE_I4 =>
TypeCode.Int32,
1133 CorElementType.ELEMENT_TYPE_U4 =>
TypeCode.UInt32,
1134 CorElementType.ELEMENT_TYPE_I8 =>
TypeCode.Int64,
1135 CorElementType.ELEMENT_TYPE_U8 =>
TypeCode.UInt64,
1215 [CLSCompliant(
false)]
1236 [CLSCompliant(
false)]
1242 [CLSCompliant(
false)]
1253 [CLSCompliant(
false)]
1271 if (enumType ==
null)
static int BinarySearch(Array array, object? value)
static void WriteUInt32BigEndian(Span< byte > destination, uint value)
static void WriteUInt16BigEndian(Span< byte > destination, ushort value)
static void WriteUInt64BigEndian(Span< byte > destination, ulong value)
static decimal ToDecimal(object? value)
static long ToInt64(object? value)
static float ToSingle(object? value)
static int ToInt32(object? value)
static short ToInt16(object? value)
static byte ToByte(object? value)
static uint ToUInt32(object? value)
static ulong ToUInt64(object? value)
static char ToChar(object? value)
static ushort ToUInt16(object? value)
static ? object ChangeType(object? value, TypeCode typeCode)
static sbyte ToSByte(object? value)
static double ToDouble(object? value)
static bool ToBoolean([NotNullWhen(true)] object? value)
static TypeCode GetTypeCode(object? value)
static object DefaultToType(IConvertible value, Type targetType, IFormatProvider provider)
readonly bool HasFlagsAttribute
EnumInfo(bool hasFlagsAttribute, ulong[] values, string[] names)
static Type GetUnderlyingType(Type enumType)
static bool IsDefined< TEnum >(TEnum value)
int CompareTo(object? target)
static string[] GetNames(Type enumType)
const char EnumSeparatorChar
static bool IsDefined(Type enumType, object value)
static bool TryParseUInt64Enum(RuntimeType enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, out ulong result)
static object Parse(Type enumType, string value)
static string InternalFlagsFormat(RuntimeType enumType, ulong result)
static ulong ToUInt64< TEnum >(TEnum value)
static object ToObject(Type enumType, char value)
static bool TryParse(Type enumType, string? value, bool ignoreCase, out object? result)
string ToString(string? format, IFormatProvider? provider)
static Array GetValues(Type enumType)
static object ToObject(Type enumType, uint value)
static object Parse(Type enumType, ReadOnlySpan< char > value)
static bool TryParseRareEnum(RuntimeType enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, [NotNullWhen(true)] out object result)
static object ToObject(Type enumType, object value)
static ulong[] InternalGetValues(RuntimeType enumType)
static bool TryParse(Type enumType, string value, bool ignoreCase, bool throwOnFailure, out object result)
static object ToObject(Type enumType, short value)
static object ToObject(Type enumType, sbyte value)
static bool TryParse< TEnum >([NotNullWhen(true)] string? value, out TEnum result)
static TEnum Parse< TEnum >(string value)
static TEnum[] GetValues< TEnum >()
override string ToString()
static bool TryParseInt64Enum(RuntimeType enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, out long result)
static object ToObject(Type enumType, byte value)
static object InternalBoxEnum(RuntimeType enumType, long value)
static string[] InternalGetNames(RuntimeType enumType)
static bool TryParseInt32Enum(RuntimeType enumType, ReadOnlySpan< char > value, int minInclusive, int maxInclusive, bool ignoreCase, bool throwOnFailure, TypeCode type, out int result)
static bool StartsNumber(char c)
static RuntimeType ValidateRuntimeType(Type enumType)
override int GetHashCode()
static object Parse(Type enumType, ReadOnlySpan< char > value, bool ignoreCase)
static string GetEnumName(EnumInfo enumInfo, ulong ulValue)
static bool TryParse(Type enumType, string? value, out object? result)
static string Format(Type enumType, object value, string format)
static bool TryParse(Type enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, out object result)
string ValueToHexString()
static ? string GetName< TEnum >(TEnum value)
static string[] GetNames< TEnum >()
static string GetEnumName(RuntimeType enumType, ulong ulValue)
static bool TryParse(Type enumType, ReadOnlySpan< char > value, out object? result)
static object ToObject(Type enumType, long value)
static string InternalFlagsFormat(EnumInfo enumInfo, ulong resultValue)
static object ToObject(Type enumType, int value)
static object ToObject(Type enumType, ushort value)
static string InternalFormat(RuntimeType enumType, ulong value)
static object ToObject(Type enumType, bool value)
static bool TryParse(Type enumType, ReadOnlySpan< char > value, bool ignoreCase, out object? result)
static RuntimeType InternalGetUnderlyingType(RuntimeType enumType)
static ? string GetName(Type enumType, object value)
static void GetEnumValuesAndNames(QCallTypeHandle enumType, ObjectHandleOnStack values, ObjectHandleOnStack names, Interop.BOOL getNames)
static bool TryParseUInt32Enum(RuntimeType enumType, ReadOnlySpan< char > value, uint maxInclusive, bool ignoreCase, bool throwOnFailure, TypeCode type, out uint result)
bool InternalHasFlag(Enum flags)
static object ToObject(Type enumType, ulong value)
string ToString(IFormatProvider? provider)
static ulong ToUInt64(object value)
static EnumInfo GetEnumInfo(RuntimeType enumType, bool getNames=true)
static string ValueToHexString(object value)
override bool Equals([NotNullWhen(true)] object? obj)
static bool TryParseByName(RuntimeType enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, out ulong result)
static object Parse(Type enumType, string value, bool ignoreCase)
string ToString(string? format)
CorElementType InternalGetCorElementType()
static CultureInfo InvariantCulture
static unsafe string ToString(ReadOnlySpan< byte > bytes, Casing casing=Casing.Upper)
static void ThrowOverflowException(TypeCode type)
static ParsingStatus TryParseUInt32IntegerStyle(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info, out uint result)
static ParsingStatus TryParseInt32IntegerStyle(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info, out int result)
static ParsingStatus TryParseUInt64IntegerStyle(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info, out ulong result)
static ParsingStatus TryParseInt64IntegerStyle(ReadOnlySpan< char > value, NumberStyles styles, NumberFormatInfo info, out long result)
override bool IsDefined(Type attributeType, bool inherit)
static string Arg_MustContainEnumInfo
static string Arg_EnumValueNotFound
static string Arg_MustBeEnum
static string Arg_MustBeType
static string InvalidCast_FromTo
static string Argument_EnumTypeDoesNotMatch
static string Arg_EnumAndObjectMustBeSameType
static string Format(string resourceFormat, object p1)
static string Arg_EnumFormatUnderlyingTypeAndObjectMustBeSameType
static string InvalidOperation_UnknownEnumType
static string Format_InvalidEnumFormatSpecification
static string Arg_MustBeEnumBaseTypeOrEnum
static ? Type GetType(string typeName, bool throwOnError, bool ignoreCase)
virtual ? string GetEnumName(object value)
virtual RuntimeTypeHandle GetTypeHandleInternal()
virtual string[] GetEnumNames()
virtual bool IsEnumDefined(object value)
static TypeCode GetTypeCode(Type? type)
virtual Type GetEnumUnderlyingType()
virtual Array GetEnumValues()
short ToInt16(IFormatProvider? provider)
char ToChar(IFormatProvider? provider)
byte ToByte(IFormatProvider? provider)
decimal ToDecimal(IFormatProvider? provider)
object ToType(Type conversionType, IFormatProvider? provider)
uint ToUInt32(IFormatProvider? provider)
DateTime ToDateTime(IFormatProvider? provider)
int ToInt32(IFormatProvider? provider)
long ToInt64(IFormatProvider? provider)
ushort ToUInt16(IFormatProvider? provider)
double ToDouble(IFormatProvider? provider)
float ToSingle(IFormatProvider? provider)
sbyte ToSByte(IFormatProvider? provider)
ulong ToUInt64(IFormatProvider? provider)
bool ToBoolean(IFormatProvider? provider)
ReadOnlySpan< T > Slice(int start)
override string ToString()