我如何获取PropertyDescriptor的属性在哪里?例如:
@H_502_2@[MyAttribute("SomeText")]
public string MyProperty
{
get{....}
set
{
// here I want to get propertyDecriptor for this property.
}
}
谢谢.
解决方法
你可以试试这个:
@H_502_2@public string Test
{
get
{
//Get properties for this
System.ComponentModel.PropertyDescriptorCollection pdc = System.ComponentModel.TypeDescriptor.GetProperties( this );
//Get property descriptor for current property
System.ComponentModel.PropertyDescriptor pd = pdc[ System.Reflection.MethodBase.GetCurrentMethod().Name ];
}
}