// Token: 0x06000F54 RID: 3924 RVA: 0x0005B0E8 File Offset: 0x000592E8 private static int?MatchName(string value, string[] enumNames, string[] resolvedNames, int valueIndex, int valueSubstringLength, StringComparison comparison) { int?result = EnumUtils.FindIndexByName(resolvedNames, value, valueIndex, valueSubstringLength, comparison); if (result == null) { result = EnumUtils.FindIndexByName(enumNames, value, valueIndex, valueSubstringLength, comparison); } return(result); }
private static int?MatchName(string value, string[] enumNames, string[] resolvedNames, int valueIndex, int valueSubstringLength, StringComparison comparison) { int?nullable = EnumUtils.FindIndexByName(resolvedNames, value, valueIndex, valueSubstringLength, comparison); if (!nullable.HasValue) { nullable = EnumUtils.FindIndexByName(enumNames, value, valueIndex, valueSubstringLength, comparison); } return(nullable); }
public static object ParseEnum(Type enumType, NamingStrategy namingStrategy, string value, bool disallowNumber) { int length = 0; ValidationUtils.ArgumentNotNull(enumType, "enumType"); ValidationUtils.ArgumentNotNull(value, "value"); if (!enumType.IsEnum()) { throw new ArgumentException("Type provided must be an Enum.", "enumType"); } EnumInfo enumInfo = EnumUtils.ValuesAndNamesPerEnum.Get(new StructMultiKey <Type, NamingStrategy>(enumType, namingStrategy)); string[] names = enumInfo.Names; string[] resolvedNames = enumInfo.ResolvedNames; ulong[] values = enumInfo.Values; int? nullable = EnumUtils.FindIndexByName(resolvedNames, value, 0, value.Length, StringComparison.Ordinal); if (nullable.HasValue) { return(Enum.ToObject(enumType, values[nullable.Value])); } int num = -1; int num1 = 0; while (true) { if (num1 >= value.Length) { break; } else if (!char.IsWhiteSpace(value[num1])) { num = num1; break; } else { num1++; } } if (num == -1) { throw new ArgumentException("Must specify valid information for parsing in the string."); } char chr = value[num]; if (char.IsDigit(chr) || chr == '-' || chr == '+') { Type underlyingType = Enum.GetUnderlyingType(enumType); value = value.Trim(); object obj = null; try { obj = Convert.ChangeType(value, underlyingType, CultureInfo.InvariantCulture); } catch (FormatException formatException) { } if (obj != null) { if (disallowNumber) { throw new FormatException("Integer string '{0}' is not allowed.".FormatWith(CultureInfo.InvariantCulture, value)); } return(Enum.ToObject(enumType, obj)); } } ulong num2 = 0L; for (int i = num; i <= value.Length; i = length + 1) { length = value.IndexOf(',', i); if (length == -1) { length = value.Length; } int num3 = length; while (i < length) { if (!char.IsWhiteSpace(value[i])) { break; } i++; } while (num3 > i && char.IsWhiteSpace(value[num3 - 1])) { num3--; } int num4 = num3 - i; nullable = EnumUtils.MatchName(value, names, resolvedNames, i, num4, StringComparison.Ordinal); if (!nullable.HasValue) { nullable = EnumUtils.MatchName(value, names, resolvedNames, i, num4, StringComparison.OrdinalIgnoreCase); } if (!nullable.HasValue) { nullable = EnumUtils.FindIndexByName(resolvedNames, value, 0, value.Length, StringComparison.OrdinalIgnoreCase); if (!nullable.HasValue) { throw new ArgumentException("Requested value '{0}' was not found.".FormatWith(CultureInfo.InvariantCulture, value)); } return(Enum.ToObject(enumType, values[nullable.Value])); } num2 |= values[nullable.Value]; } return(Enum.ToObject(enumType, num2)); }
// Token: 0x06000F53 RID: 3923 RVA: 0x0005AE9C File Offset: 0x0005909C public static object ParseEnum(Type enumType, [Nullable(2)] NamingStrategy namingStrategy, string value, bool disallowNumber) { ValidationUtils.ArgumentNotNull(enumType, "enumType"); ValidationUtils.ArgumentNotNull(value, "value"); if (!enumType.IsEnum()) { throw new ArgumentException("Type provided must be an Enum.", "enumType"); } EnumInfo enumInfo = EnumUtils.ValuesAndNamesPerEnum.Get(new StructMultiKey <Type, NamingStrategy>(enumType, namingStrategy)); string[] names = enumInfo.Names; string[] resolvedNames = enumInfo.ResolvedNames; ulong[] values = enumInfo.Values; int? num = EnumUtils.FindIndexByName(resolvedNames, value, 0, value.Length, StringComparison.Ordinal); if (num != null) { return(Enum.ToObject(enumType, values[num.Value])); } int num2 = -1; int i = 0; while (i < value.Length) { if (char.IsWhiteSpace(value[i])) { i++; } else { num2 = i; IL_A9: if (num2 == -1) { throw new ArgumentException("Must specify valid information for parsing in the string."); } char c = value[num2]; if (char.IsDigit(c) || c == '-' || c == '+') { Type underlyingType = Enum.GetUnderlyingType(enumType); value = value.Trim(); object obj = null; try { obj = Convert.ChangeType(value, underlyingType, CultureInfo.InvariantCulture); } catch (FormatException) { } if (obj != null) { if (disallowNumber) { throw new FormatException("Integer string '{0}' is not allowed.".FormatWith(CultureInfo.InvariantCulture, value)); } return(Enum.ToObject(enumType, obj)); } } ulong num3 = 0UL; int j = num2; while (j <= value.Length) { int num4 = value.IndexOf(',', j); if (num4 == -1) { num4 = value.Length; } int num5 = num4; while (j < num4 && char.IsWhiteSpace(value[j])) { j++; } while (num5 > j && char.IsWhiteSpace(value[num5 - 1])) { num5--; } int valueSubstringLength = num5 - j; num = EnumUtils.MatchName(value, names, resolvedNames, j, valueSubstringLength, StringComparison.Ordinal); if (num == null) { num = EnumUtils.MatchName(value, names, resolvedNames, j, valueSubstringLength, StringComparison.OrdinalIgnoreCase); } if (num != null) { num3 |= values[num.Value]; j = num4 + 1; } else { num = EnumUtils.FindIndexByName(resolvedNames, value, 0, value.Length, StringComparison.OrdinalIgnoreCase); if (num == null) { throw new ArgumentException("Requested value '{0}' was not found.".FormatWith(CultureInfo.InvariantCulture, value)); } return(Enum.ToObject(enumType, values[num.Value])); } } return(Enum.ToObject(enumType, num3)); } } goto IL_A9; }