Property Descriptor如何使用相同的代码行获取两个控件的值?

我在Ex-Employee开发的项目之一中找到了这个代码,用于自定义gridview和自定义控件,但是我不确定它究竟是做什么的,

代码

public class aBoundField : ImageField { //here I got some get set properties defined protected override void OnDataBindField(object sender, EventArgs e) { Control control = (Control)sender; PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true); PropertyDescriptor propertyB = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true); PropertyAFieldValue = this.GetValue(control.NamingContainer, this._PropertyAField, ref propertyA).ToString(); PropertyBFieldValue = this.GetValue(control.NamingContainer, this._PropertyBField, ref propertyB).ToString(); base.OnDataBindField(sender, e); } 

OnDataBindField方法中发生了什么,尤其是在获取PropertyDescriptor时。 我做了一点研究,发现它是一个属性包,但如果它是一个属性包,它将如何知道此代码中属性A或属性B的值。

  PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true); PropertyDescriptor propertyB = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true); 

我不太清楚的是

Property Descriptor如何使用相同的代码行获取两个控件的值

 TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true) 

上面的代码行将如何确定它的属性A或属性B.

我试图从一个属性描述符中获取值,认为它是一个属性包,但它没有正常工作。

 GetValue(control.NamingContainer, this._PropertyAField, ref propertyA) 

ProperyA作为参考给出了属性中发生的一切,该方法内部将更新上面定义的propertyA。

运用

 PropertyDescriptor propertyA = null; 

代替

 PropertyDescriptor propertyA = TypeDescriptor.GetProperties(DataBinder.GetDataItem(control.NamingContainer)).Find("boundField", true); 

仍然有效。

进一步阅读
ref方法参数关键字

鉴于您最近的编辑:

Property Descriptor如何使用相同的代码行获取两个控件的值

它不能。 出于某种原因,前雇员希望propertyApropertyB都相同或者有一个拼写错误,这实际上是某种错误。