如何获得类型的成员,忽略其值?
public static class Program
{
public static String a {set; get;}
public static void Main()
{
a = null;
a.GetType(); //Cant do that, it's null, how can i get "String"?
}
}
答案 0 :(得分:4)
在没有实例的情况下获取它的类型的唯一方法是使用声明类型:
var type = typeof(Program)
.GetProperty("a", BindingFlags.Static | BindingFlags.Public)
.PropertyType;