Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get PropertyDescriptor for current property?

How can I get the PropertyDescriptor for the current property? For example:

[MyAttribute("SomeText")]
public string MyProperty
{
    get{....}
    set
    {
        // here I want to get PropertyDescriptor for this property.
    }
}
like image 601
Yuriy Avatar asked Jan 18 '11 10:01

Yuriy


People also ask

How do you become a property descriptor?

To access the property descriptor of property, we need to use a static method provided by the Object. The Object. getOwnPropertyDescriptor method returns the property descriptor of the prop which is the property name on the obj object. Object.

What is PropertyDescriptor C#?

PropertyDescriptors allows the manipulation of a model's properties (also called parameters) via gui widgets displayed on the parameter's tab pane. You can also use PropertyDescriptors in conjunction with an agent's parameters. More on that at the end of this document.

What is PropertyDescriptor in typescript?

A PropertyDescriptor describes a property on an Object . Any JavaScript object can be used as a PropertyDescriptor where unspecified properties will be treated as undefined or false .


1 Answers

You could try this:


        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 ];
            }
        }
like image 61
WraithNath Avatar answered Sep 23 '22 18:09

WraithNath