I\'m working on an app in C# (Windows-Phone-7), and I\'m trying to do something simple that has me stumped.
I want to cycle through each Color in Colors, and write o
You can use this helper method to get a Dictionary of each Color's name/value pair.
public static Dictionary GetStaticPropertyBag(Type t)
{
const BindingFlags flags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
var map = new Dictionary();
foreach (var prop in t.GetProperties(flags))
{
map[prop.Name] = prop.GetValue(null, null);
}
return map;
}
Use is with:
var colors = GetStaticPropertyBag(typeof(Colors));
foreach(KeyValuePair colorPair in colors)
{
Console.WriteLine(colorPair.Key);
Color color = (Color) colorPair.Value;
}
Credit for the helper method goes to How can I get the name of a C# static class property using reflection?