小编Den*_*hin的帖子

PropertyInfo.GetSetMethod(true)不返回基类属性的方法

我有以下测试程序:

public class FooBase
{
  public object Prop {
    get { return null; }
    private set { } 
  }
}
public class Foo :FooBase
{
}
class Program
{
  static void Main(string[] args)
  {
    MethodInfo setMethod = typeof(Foo).GetProperty("Prop").GetSetMethod(true);
    if (setMethod==null)
      Console.WriteLine("NULL");
    else
      Console.WriteLine(setMethod.ToString());
    Console.ReadKey(); 
  }
}
Run Code Online (Sandbox Code Playgroud)

如果我运行它会显示"NULL".如果我将属性定义移动到类Foo,那么我按预期工作.这是.NET中的错误吗?

.net reflection

6
推荐指数
2
解决办法
1273
查看次数

标签 统计

.net ×1

reflection ×1