.NET Framework
asp.net mvc 1.0 IEnumerable for struct(enum)
Sunny's
2009. 4. 28. 09:08
asp.net mvc 1.0 IEnumerable for struct(enum)
public class EnumHelper
{
public static IEnumerable<ListItem> Enumerate<T>() where T : struct
{
foreach (int value in Enum.GetValues(typeof(T)))
yield return new ListItem(value.ToString(), Enum.GetName(typeof(T), value));
}
}
{
public static IEnumerable<ListItem> Enumerate<T>() where T : struct
{
foreach (int value in Enum.GetValues(typeof(T)))
yield return new ListItem(value.ToString(), Enum.GetName(typeof(T), value));
}
}
public class ListItem
{
public string Value{get;set;}
public string Text{get;set;}
public ListItem(string v, string t)
{
this.Value = v;
this.Text = t;
}
}
SelectList(EnumHelper.Enumerate<ProjTaskState>(), "Value", "Text");