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); }
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); }
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])); }