How do I call a static property of a generic class with reflection?

前端 未结 4 1817
暗喜
暗喜 2021-01-04 20:30

I have a class (that I cannot modify) that simplifies to this:

public class Foo {
    public static string MyProperty {
         get {return \"Metho         


        
4条回答
  •  长发绾君心
    2021-01-04 20:47

    typeof(Foo<>)
        .MakeGenericType(typeof(string))
        .GetProperty("MyProperty")
        .GetValue(null, null);
    

提交回复
热议问题