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

◆ TryParseRareEnum()

static bool System.Enum.TryParseRareEnum ( RuntimeType enumType,
ReadOnlySpan< char > value,
bool ignoreCase,
bool throwOnFailure,
[NotNullWhen(true)] out object result )
inlinestaticprivate

Definition at line 759 of file Enum.cs.

760 {
761 if (StartsNumber(value[0]))
762 {
763 Type underlyingType = GetUnderlyingType(enumType);
764 try
765 {
766 result = ToObject(enumType, Convert.ChangeType(value.ToString(), underlyingType, CultureInfo.InvariantCulture));
767 return true;
768 }
769 catch (FormatException)
770 {
771 }
772 catch when (!throwOnFailure)
773 {
774 result = null;
775 return false;
776 }
777 }
778 if (TryParseByName(enumType, value, ignoreCase, throwOnFailure, out var result2))
779 {
780 try
781 {
782 result = ToObject(enumType, result2);
783 return true;
784 }
785 catch when (!throwOnFailure)
786 {
787 }
788 }
789 result = null;
790 return false;
791 }
static Type GetUnderlyingType(Type enumType)
Definition Enum.cs:309
static object ToObject(Type enumType, object value)
Definition Enum.cs:874
static bool StartsNumber(char c)
Definition Enum.cs:865
static bool TryParseByName(RuntimeType enumType, ReadOnlySpan< char > value, bool ignoreCase, bool throwOnFailure, out ulong result)
Definition Enum.cs:793
static CultureInfo InvariantCulture

References System.Convert.ChangeType(), System.Enum.GetUnderlyingType(), System.Globalization.CultureInfo.InvariantCulture, System.Enum.StartsNumber(), System.Enum.ToObject(), System.Enum.TryParseByName(), and System.value.

Referenced by System.Enum.TryParse(), and System.Enum.TryParse< TEnum >().