views:

81

answers:

1

Let's say I have a function that takes a string. That string contains the fully name of an enum type (e.g. "MyCompany.Area.AotherNamespace.MyEnum").

How could I create an array of strings (or List<string>) whose elements are the values of MyCompany.Area.AotherNamespace.MyEnum?

Is that even possible?

I'm basically trying to serialize an enum type serverside and then output it in clientside JavaScript so I don't have to define an enum in two places--in my C# and my JavaScript.

+4  A: 
Type type = Type.GetType(yourStringWithTheFullEnumName);
string[] valueNames = Enum.GetNames(type);

This doesn't work in Silverlight (and possibly the Compact Framework). If you are working in an "alternative" CLR, then you can get the same effect with a tad bit of reflection.

Matt Greer