我有以下测试程序:
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中的错误吗?