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

前端 未结 4 1798
暗喜
暗喜 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:34

    You need something like this:

    typeof(Foo)
        .GetProperty("MyProperty")
        .GetGetMethod()
        .Invoke(null, new object[0]);
    

提交回复
热议问题