示例#1
0
            private static IReadOnlyDictionary <string, TEnum> GetNameValuesCore(Type enumType, bool ignoreCase)
            {
                var result =
#if FW40
                    new DictionaryWithReadOnly <string, TEnum>(ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
#else
                    new Dictionary <string, TEnum>(ignoreCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
#endif

                if (enumType.IsEnum)
                {
                    var names  = Enum.GetNames(enumType);
                    var values = (TEnum[])Enum.GetValues(enumType);
                    for (var i = 0; i < names.Length; i++)
                    {
                        // DONTTOUCH: case may be ignored
                        if (result.ContainsKey(names[i]))
                        {
                            continue;
                        }

                        result.Add(names[i], values[i]);
                    }
                }
                return(result);
            }
示例#2
0
            private static IReadOnlyDictionary <TEnum, string> GetValueNamesCore(Type enumType)
            {
                var result =
#if FW40
                    new DictionaryWithReadOnly <TEnum, string>();
#else
                    new Dictionary <TEnum, string>();
#endif

                if (enumType.IsEnum)
                {
                    var names  = Enum.GetNames(enumType);
                    var values = (TEnum[])Enum.GetValues(enumType);
                    for (var i = 0; i < names.Length; i++)
                    {
                        if (result.ContainsKey(values[i]))
                        {
                            continue;
                        }

                        result.Add(values[i], names[i]);
                    }
                }
                return(result);
            }