我使用的是TypeDescriptor.GetProperties(instance)
,它从基类返回所有属性和get/set方法。PropertyDescriptor和继承
我有基类:
public class Foo
{
public virtual string Name
{
get => _name;
set => _name = value;
}
}
Derrived类:
public class Bar : Foo
{
public override string Name => "Test";
}
当我得到了 '名称' 属性PropertyDescriptor.IsReadOnly
信息等于 '假',但它应该是“真”。 我该如何设置'PropertyDescriptor',这样它会返回我的数据只用于耙类类型?
可能重复[获取通过类的反射属性,但不是从继承类](https://stackoverflow.com/questions/7596162/get-by-reflection-properties-of-class-but-not-from -herherited-class) –
@BradleyUffner nope,那不是我的情况。 – Sigin
啊,对不起,你说得对。撤回近距离投票。 –