45 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Text;
 | |
| using System.Reflection;
 | |
| using System.ComponentModel;
 | |
| 
 | |
| namespace VEPROMS.CSLA.Library
 | |
| {
 | |
| 	public class EnumDetail<T>
 | |
| 	{
 | |
| 		private T _EValue;
 | |
| 		public T EValue
 | |
| 		{
 | |
| 			get { return _EValue; }
 | |
| 			set { _EValue = value; }
 | |
| 		}
 | |
| 		private string _Name;
 | |
| 
 | |
| 		public string Name
 | |
| 		{
 | |
| 			get { return _Name; }
 | |
| 			set { _Name = value; }
 | |
| 		}
 | |
| 		public EnumDetail(string name, T eValue)
 | |
| 		{
 | |
| 			_Name = name;
 | |
| 			_EValue = eValue;
 | |
| 		}
 | |
| 		public static EnumDetail<T>[] Details()
 | |
| 		{
 | |
| 			string[] names = Enum.GetNames(typeof(T));
 | |
| 			Array values = Enum.GetValues(typeof(T));
 | |
| 			EnumDetail<T>[] retval = new EnumDetail<T>[values.Length];
 | |
| 			for (int i = 0; i < values.Length; i++)
 | |
| 			{
 | |
| 				T val = (T)values.GetValue(i);
 | |
| 				FieldInfo fi = val.GetType().GetField(val.ToString());
 | |
| 				DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
 | |
| 				retval[i] = new EnumDetail<T>(((attributes.Length > 0) ? attributes[0].Description : names[i]), (T)values.GetValue(i));
 | |
| 			}
 | |
| 			return retval;
 | |
| 		}
 | |
| 	}
 | |
| }
 | 
