CodeKiwi
CodeKiwi

Reputation: 749

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.

Upvotes: 10

Views: 3117

Answers (2)

Stuart
Stuart

Reputation: 66882

Why is Enum.GetValues() not available in the Windows Phone 7 API

The "Why" is because WP7 is based on the "Compact Framework" - to save on resources, the compact framework does not contain every method in the full framework - and Enum.GetValues() was one of those omitted.

does this mean I should generally shy away from Enums in favor of structs or other mechanisms.

No - no particular reason. I'd recommend you continue to use enum's where you find them the most appropriate programming solution.

Upvotes: 5

Chris Sainty
Chris Sainty

Reputation: 9326

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.

Upvotes: 15

Related Questions