Beispiel #1
0
        public static string GetStringValue(Enum Value)
        {
            FieldInfo info = Value.GetType().GetFields()
                             .Where(o => o.Name == Value.ToString())
                             .FirstOrDefault();

            return(EnumStringValue.GetStringValue(info));
        }
Beispiel #2
0
        public static IList <KeyValuePair <string, int> > ToList(Type EnumType)
        {
            if (EnumType == null)
            {
                throw new ArgumentNullException("type");
            }

            List <KeyValuePair <string, int> > list = new List <KeyValuePair <string, int> >();

            foreach (FieldInfo item in EnumType.GetFields().Where(o => o.Name != "value__"))
            {
                int    value = Convert.ToInt32(Enum.Parse(EnumType, item.Name, true));
                string name  = EnumStringValue.GetStringValue(item);
                list.Add(new KeyValuePair <string, int>(name, value));
            }

            return(list);
        }
Beispiel #3
0
        public static Enum Parse(Type EnumType, string Value)
        {
            IList <KeyValuePair <string, int> > enumValues = EnumStringValue.ToList(EnumType);

            return((Enum)Enum.ToObject(EnumType, enumValues.Where(o => o.Key == Value).First().Value));
        }