M
Mythran
System.Drawing.SystemColors is a class with all static properties. Here is
what my short-ranged goal is...
I want to enumerate all of the SystemColors properties and print the name
(using reflection), and I am able to do this:
PropertyInfo[] props = typeof(SystemColors).GetProperties();
foreach (PropertyInfo prop in props) {
Console.WriteLine(prop.Name);
}
This works fine...now, in the same method, I want to get the value of each
property, which I can using the following:
SystemColors colors = null;
foreach (PropertyInfo prop in props) {
Console.WriteLine(prop.GetValue(null, null).ToString());
}
Now heres the problem, I want to pass the class to the method, so that the
class can be System.Drawing.Colors or System.Drawing.SystemColors, etc...
public static void DisplayColors(object Instance)
{
PropertyInfo[] props = Instance.GetType().GetProperties();
foreach (PropertyInfo prop in props) {
Console.WriteLine(
"Name: {0} - Value: {1}",
prop.Name, prop.GetValue(null, null).ToString()
);
}
}
What do I pass to the DisplayColors method? I can't pass
System.Drawing.SystemColors because it's a not-creatable class? How can I
get a reference to the static instance so I can pass it to DisplayColors?
Thanks,
Mythran
what my short-ranged goal is...
I want to enumerate all of the SystemColors properties and print the name
(using reflection), and I am able to do this:
PropertyInfo[] props = typeof(SystemColors).GetProperties();
foreach (PropertyInfo prop in props) {
Console.WriteLine(prop.Name);
}
This works fine...now, in the same method, I want to get the value of each
property, which I can using the following:
SystemColors colors = null;
foreach (PropertyInfo prop in props) {
Console.WriteLine(prop.GetValue(null, null).ToString());
}
Now heres the problem, I want to pass the class to the method, so that the
class can be System.Drawing.Colors or System.Drawing.SystemColors, etc...
public static void DisplayColors(object Instance)
{
PropertyInfo[] props = Instance.GetType().GetProperties();
foreach (PropertyInfo prop in props) {
Console.WriteLine(
"Name: {0} - Value: {1}",
prop.Name, prop.GetValue(null, null).ToString()
);
}
}
What do I pass to the DisplayColors method? I can't pass
System.Drawing.SystemColors because it's a not-creatable class? How can I
get a reference to the static instance so I can pass it to DisplayColors?
Thanks,
Mythran