예제 #1
0
        public static IDictionary <string, int> GetNamePairs(Type type)
        {
            var pairs = new Dictionary <string, int>();

            var values = (int[])Enum.GetValues(type);

            values.Each(value => pairs[StringHelper.ToPureUpper(Enum.Parse(type, value.ToString()))] = value);

            return(pairs);
        }
예제 #2
0
        public static IDictionary <string, int> GetDescriptionPairs <T>() where T : struct, IConvertible
        {
            ThrowIfNotEnum <T>();

            var pairs = new Dictionary <string, int>();

            var values = (int[])Enum.GetValues(typeof(T));

            values.Each(value => pairs[StringHelper.ToPureUpper(GetDescription <T>(value))] = value);

            return(pairs);
        }
예제 #3
0
        public static IEnumerable <int> GetValues <T>(string keys) where T : struct, IConvertible
        {
            if (string.IsNullOrEmpty(keys))
            {
                return(new List <int>());
            }

            var pairs     = GetNamePairs <T>();
            var upperKeys = StringHelper.ToPureUpper(keys);

            return(upperKeys.Split(',').Where(key => pairs.ContainsKey(key)).Select(key => pairs[key]));
        }