Files
SourceCode/PROMS/VEPROMS.CSLA.Library/Config/EnumDetail.cs
T
2026-08-28 11:15:35 -04:00

33 lines
928 B
C#

using System;
using System.Reflection;
using System.ComponentModel;
namespace VEPROMS.CSLA.Library
{
public class EnumDetail<T>
{
public T EValue { get; set; }
public string Name { get; set; }
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;
}
}
}