I have an enumeration for my Things like so:
public enum Things
{
OneThing,
AnotherThing
}
I would like to write an extension method
In my opinion, this is the cleanest way. Why?
System.Enum
new
and that's a small trade off (because it has to have an instance in order to work.null
around and it literally won't compile if you try to use it with another type.Usage:
(new Things()).ToSelectList()
Extension Method:
[Extension()]
public SelectList ToSelectList(System.Enum source)
{
var values = from Enum e in Enum.GetValues(source.GetType)
select new { ID = e, Name = e.ToString() };
return new SelectList(values, "Id", "Name");
}