How to get fields and their values from a static class in referenced assembly
Using reflection, you will need to look for fields; these are not properties. As you can see from the following code, it looks for public static members:
class Program
{
static void Main(string[] args)
{
Type t = typeof(A7);
FieldInfo[] fields = t.GetFields(BindingFlags.Static | BindingFlags.Public);
foreach (FieldInfo fi in fields)
{
Console.WriteLine(fi.Name);
Console.WriteLine(fi.GetValue(null).ToString());
}
Console.Read();
}
}
I faced the same issue when i tried to get the properties using this syntax (where "ConfigValues" is a static class with static properties and I am looking for a property with the name "LookingFor")
PropertyInfo propertyInfo = ConfigValues.GetType().GetProperties().SingleOrDefault(p => p.Name == "LookingFor");
The solution was to use the typeof operator instead
PropertyInfo propertyInfo = typeof(ConfigValues).GetProperties().SingleOrDefault(p => p.Name == "LookingFor");
that works, you don't have to view them as fields
HTH