Get Key Value Pair from Enum

public static List<KeyValuePair<string, int>> GetKeyValuePairFromEnum<T>() where T : struct, IConvertible
		{
			List<KeyValuePair<string, int>> result = new List<KeyValuePair<string, int>>();

			IEnumerable<T> array = Enum.GetValues(typeof(T)).Cast<T>();

			foreach (T item in array)
			{
				string name = item.ToString();
				int value = (int)Enum.Parse(typeof(T), name);

				KeyValuePair<string, int> pair = new KeyValuePair<string, int>(name, value);
				result.Add(pair);
			}

			return result;
		}

  

posted on 2011-09-22 08:24  Cooldash  阅读(330)  评论(0)    收藏  举报

导航