Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum.GetValues in WP7

Why is Enum.GetValues() not available in the Windows Phone 7 API, and does this mean I should generally shy away from Enums in favor of structs or other mechanisms.

like image 330
CodeKiwi Avatar asked May 04 '11 05:05

CodeKiwi


People also ask

What does enum GetValues return?

The GetValues method returns an array that contains a value for each member of the enumType enumeration. If multiple members have the same value, the returned array includes duplicate values.

Does enum GetValues use reflection?

Roughly, yes. There are two kind of reflection code, the general kind that goes through RuntimeType and the specific kind that uses dedicated CLR helper functions. The latter uses type info that can retrieved from the internal type representation that the CLR maintains. The fast kind.


1 Answers

I've run into this. For my purposes I was able to use reflection

foreach (var x in typeof(MyEnum).GetFields()) {
  if (x.IsLiteral) {
    // Do my stuff here
  }
}

Really depends what you are doing with them though.

like image 144
Chris Sainty Avatar answered Nov 16 '22 02:11

Chris Sainty