我已经在我的基类中设置了我的一个属性来拥有一个受保护的设置器。这工作正常,我可以在派生类的构造函数中设置属性 - 但是当我尝试使用 PropertyDescriptorCollection 设置此属性时,它不会设置,但是使用该集合适用于所有其他属性。
我应该提到,当我删除受保护的访问修饰符时,一切正常......但当然现在它不受保护。感谢您的任何意见。
class base_a
{
public string ID { get; protected set; }
public virtual void SetProperties(string xml){}
}
class derived_a : base_a
{
public derived_a()
{
//this works fine
ID = "abc"
}
public override void SetProperties(string xml)
{
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(this);
//this does not work...no value set.
pdc["ID"].SetValue(this, "abc");
}
}