I'm trying to get the names of the people in the below class. I can get the list of PropertyInfo just fine, indicating that People has Bob and Sally, but I can't get references to Bob and Sally. How do I do that?
public static class People
{
public static Person Bob { get; }
public static Person Sally { get; }
}
PropertyInfo[] properties = typeof(People).GetProperties();
foreach (PropertyInfo info in properties)
{
if (info.PropertyType == typeof(Person))
{
// how do I get a reference to the person here?
Person c = info.GetValue(?????, ?????) as Person;
if (null != c)
{
Console.WriteLine(c.Name);
}
}
}
edit changed null == c to null != c to get console.writeline to execute