C#get member的类型忽略它的值?

时间:2014-08-30 19:14:23

标签: c# .net reflection types member

如何获得类型的成员,忽略其

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"?
    }

}

1 个答案:

答案 0 :(得分:4)

在没有实例的情况下获取它的类型的唯一方法是使用声明类型:

var type = typeof(Program)
     .GetProperty("a", BindingFlags.Static | BindingFlags.Public)
     .PropertyType;