0

How can I get a Type of member, ignoring its value ?

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

}
user3325976
  • 799
  • 1
  • 6
  • 16

1 Answers1

4

The only way to get it's type without an instance is using the declaring type:

var type = typeof(Program)
     .GetProperty("a", BindingFlags.Static | BindingFlags.Public)
     .PropertyType;
Selman Genç
  • 100,147
  • 13
  • 119
  • 184