private static bool TryResolvedEnumName( BidirectionalDictionary <string, string> map, string enumText, out string resolvedEnumName) { if (map.TryGetBySecond(enumText, out resolvedEnumName)) { return(true); } resolvedEnumName = (string)null; return(false); }
public static string ToEnumName(Type enumType, string enumText, bool camelCaseText) { BidirectionalDictionary <string, string> bidirectionalDictionary = EnumUtils.EnumMemberNamesPerType.Get(enumType); string[] strArray = enumText.Split(','); for (int index = 0; index < strArray.Length; ++index) { string first = strArray[index].Trim(); string second; bidirectionalDictionary.TryGetByFirst(first, out second); second = second ?? first; if (camelCaseText) { second = StringUtils.ToCamelCase(second); } strArray[index] = second; } return(string.Join(", ", strArray)); }
private static BidirectionalDictionary <string, string> InitializeEnumType( Type type) { BidirectionalDictionary <string, string> bidirectionalDictionary = new BidirectionalDictionary <string, string>((IEqualityComparer <string>)StringComparer.Ordinal, (IEqualityComparer <string>)StringComparer.Ordinal); foreach (FieldInfo field in type.GetFields(BindingFlags.Static | BindingFlags.Public)) { string name1 = field.Name; string name2 = field.Name; string first; if (bidirectionalDictionary.TryGetBySecond(name2, out first)) { throw new InvalidOperationException( "Enum name '{0}' already exists on enum '{1}'.".FormatWith((IFormatProvider)CultureInfo.InvariantCulture, (object)name2, (object)type.Name)); } bidirectionalDictionary.Set(name1, name2); } return(bidirectionalDictionary); }