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

◆ TryParse() [1/6]

static bool System.Enum.TryParse ( Type enumType,
ReadOnlySpan< char > value,
bool ignoreCase,
bool throwOnFailure,
out object result )
inlinestaticprivate

Definition at line 450 of file Enum.cs.

451 {
452 RuntimeType runtimeType = ValidateRuntimeType(enumType);
453 value = value.TrimStart();
454 if (value.Length == 0)
455 {
456 if (throwOnFailure)
457 {
458 throw new ArgumentException(SR.Arg_MustContainEnumInfo, "value");
459 }
460 result = null;
461 return false;
462 }
463 int result3;
464 uint result4;
465 switch (Type.GetTypeCode(runtimeType))
466 {
467 case TypeCode.SByte:
468 {
469 bool flag = TryParseInt32Enum(runtimeType, value, -128, 127, ignoreCase, throwOnFailure, TypeCode.SByte, out result3);
470 result = (flag ? InternalBoxEnum(runtimeType, result3) : null);
471 return flag;
472 }
473 case TypeCode.Int16:
474 {
475 bool flag = TryParseInt32Enum(runtimeType, value, -32768, 32767, ignoreCase, throwOnFailure, TypeCode.Int16, out result3);
476 result = (flag ? InternalBoxEnum(runtimeType, result3) : null);
477 return flag;
478 }
479 case TypeCode.Int32:
480 {
481 bool flag = TryParseInt32Enum(runtimeType, value, int.MinValue, int.MaxValue, ignoreCase, throwOnFailure, TypeCode.Int32, out result3);
482 result = (flag ? InternalBoxEnum(runtimeType, result3) : null);
483 return flag;
484 }
485 case TypeCode.Byte:
486 {
487 bool flag = TryParseUInt32Enum(runtimeType, value, 255u, ignoreCase, throwOnFailure, TypeCode.Byte, out result4);
488 result = (flag ? InternalBoxEnum(runtimeType, result4) : null);
489 return flag;
490 }
491 case TypeCode.UInt16:
492 {
493 bool flag = TryParseUInt32Enum(runtimeType, value, 65535u, ignoreCase, throwOnFailure, TypeCode.UInt16, out result4);
494 result = (flag ? InternalBoxEnum(runtimeType, result4) : null);
495 return flag;
496 }
497 case TypeCode.UInt32:
498 {
499 bool flag = TryParseUInt32Enum(runtimeType, value, uint.MaxValue, ignoreCase, throwOnFailure, TypeCode.UInt32, out result4);
500 result = (flag ? InternalBoxEnum(runtimeType, result4) : null);
501 return flag;
502 }
503 case TypeCode.Int64:
504 {
505 long result5;
506 bool flag = TryParseInt64Enum(runtimeType, value, ignoreCase, throwOnFailure, out result5);
507 result = (flag ? InternalBoxEnum(runtimeType, result5) : null);
508 return flag;
509 }
510 case TypeCode.UInt64:
511 {
512 ulong result2;
513 bool flag = TryParseUInt64Enum(runtimeType, value, ignoreCase, throwOnFailure, out result2);
514 result = (flag ? InternalBoxEnum(runtimeType, (long)result2) : null);
515 return flag;
516 }
517 default:
518 return TryParseRareEnum(runtimeType, value, ignoreCase, throwOnFailure, out result);
519 }
520 }
static bool TryParseUInt64Enum(RuntimeType enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, out ulong result)
Definition Enum.cs:733
static bool TryParseRareEnum(RuntimeType enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, [NotNullWhen(true)] out object result)
Definition Enum.cs:759
static bool TryParseInt64Enum(RuntimeType enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, out long result)
Definition Enum.cs:705
static object InternalBoxEnum(RuntimeType enumType, long value)
static bool TryParseInt32Enum(RuntimeType enumType, ReadOnlySpan< char > value, int minInclusive, int maxInclusive, bool ignoreCase, bool throwOnFailure, TypeCode type, out int result)
Definition Enum.cs:641
static RuntimeType ValidateRuntimeType(Type enumType)
Definition Enum.cs:1269
static bool TryParseUInt32Enum(RuntimeType enumType, ReadOnlySpan< char > value, uint maxInclusive, bool ignoreCase, bool throwOnFailure, TypeCode type, out uint result)
Definition Enum.cs:673

References System.SR.Arg_MustContainEnumInfo, System.Type.GetTypeCode(), System.Enum.InternalBoxEnum(), System.Reflection.MaxValue, System.Enum.TryParseInt32Enum(), System.Enum.TryParseInt64Enum(), System.Enum.TryParseRareEnum(), System.Enum.TryParseUInt32Enum(), System.Enum.TryParseUInt64Enum(), System.Enum.ValidateRuntimeType(), and System.value.