Created
October 11, 2012 14:09
-
-
Save peteraritchie/3872561 to your computer and use it in GitHub Desktop.
convert enum value to SelectList of all enum's values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static SelectList ToSelectList<T>(this T value) where T : struct | |
{ | |
if(!value.GetType().IsEnum) throw new ArgumentException("bad arg", "value"); | |
var c = Enum.GetValues(value.GetType()); | |
return new SelectList(c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
That is similar to what I was playing around with but you still need to call it like
var x = MyEnum.SomeValue.ToSelectList();
I was hoping to just say
var x = MyEnum.ToSelectList(); or var x = EnumEx.ToSelectList(MyEnum);
But it doesn't let you. I think I understand why...but I still think it's dumb.