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

◆ TryParseByName()

static bool System.Enum.TryParseByName ( RuntimeType enumType,
ReadOnlySpan< char > value,
bool ignoreCase,
bool throwOnFailure,
out ulong result )
inlinestaticprivate

Definition at line 793 of file Enum.cs.

794 {
795 ReadOnlySpan<char> readOnlySpan = value;
796 EnumInfo enumInfo = GetEnumInfo(enumType);
797 string[] names = enumInfo.Names;
798 ulong[] values = enumInfo.Values;
799 bool flag = true;
800 ulong num = 0uL;
801 while (value.Length > 0)
802 {
803 int num2 = value.IndexOf(',');
804 ReadOnlySpan<char> span;
805 if (num2 == -1)
806 {
807 span = value.Trim();
808 value = default(ReadOnlySpan<char>);
809 }
810 else
811 {
812 if (num2 == value.Length - 1)
813 {
814 flag = false;
815 break;
816 }
817 span = value.Slice(0, num2).Trim();
818 value = value.Slice(num2 + 1);
819 }
820 bool flag2 = false;
821 if (ignoreCase)
822 {
823 for (int i = 0; i < names.Length; i++)
824 {
825 if (span.EqualsOrdinalIgnoreCase(names[i]))
826 {
827 num |= values[i];
828 flag2 = true;
829 break;
830 }
831 }
832 }
833 else
834 {
835 for (int j = 0; j < names.Length; j++)
836 {
837 if (span.EqualsOrdinal(names[j]))
838 {
839 num |= values[j];
840 flag2 = true;
841 break;
842 }
843 }
844 }
845 if (!flag2)
846 {
847 flag = false;
848 break;
849 }
850 }
851 if (flag)
852 {
853 result = num;
854 return true;
855 }
856 if (throwOnFailure)
857 {
858 throw new ArgumentException(SR.Format(SR.Arg_EnumValueNotFound, readOnlySpan.ToString()));
859 }
860 result = 0uL;
861 return false;
862 }
static EnumInfo GetEnumInfo(RuntimeType enumType, bool getNames=true)
Definition Enum.cs:51

References System.SR.Arg_EnumValueNotFound, System.SR.Format(), System.Enum.GetEnumInfo(), System.Enum.EnumInfo.Names, System.ReadOnlySpan< T >.Slice(), System.ReadOnlySpan< T >.ToString(), System.value, System.Enum.EnumInfo.Values, and System.values.

Referenced by System.Enum.TryParseInt32Enum(), System.Enum.TryParseInt64Enum(), System.Enum.TryParseRareEnum(), System.Enum.TryParseUInt32Enum(), and System.Enum.TryParseUInt64Enum().