c# – 如何获取当前属性的PropertyDescriptor?
发布时间:2020-12-15 06:49:34 所属栏目:百科 来源:网络整理
导读:我如何获取PropertyDescriptor的属性在哪里?例如: [MyAttribute("SomeText")]public string MyProperty{get{....}set{ // here I want to get propertyDecriptor for this property.}} 谢谢. 解决方法 你可以试试这个: public string Test { get { //Get
我如何获取PropertyDescriptor的属性在哪里?例如:
[MyAttribute("SomeText")] public string MyProperty { get{....} set { // here I want to get propertyDecriptor for this property. } } 谢谢. 解决方法
你可以试试这个:
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 ]; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |