Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8439595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:02:24+00:00 2026-06-10T08:02:24+00:00

I want to add some custom PropertyGrid-centric Attributes to the object’s properties, to provide

  • 0

I want to add some custom PropertyGrid-centric Attributes to the object’s properties, to provide richer editing, hide some values and group them in categories, because that class I’m working with doesn’t provide such functionality and I can’t do anything about it.

Really, it’s for MS’s Application Settings that generates code, so you can’t extend it in any way property-wise. See my other question: Runtime AppSettings.settings editor dialog

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:02:26+00:00Added an answer on June 10, 2026 at 8:02 am

    Unlike others have suggested, it’s quite possible, and also not that hard. For example, you want to add some new attributes to some properties, which you can select at runtime based on some criteria.

    There’re two helper classes we’ll need to implement this.

    First goes PropertyOverridingTypeDescriptor, it allows us to supply our own property descriptors for some properties, while keeping others intact:

    public class PropertyOverridingTypeDescriptor : CustomTypeDescriptor
        {
            private readonly Dictionary<string, PropertyDescriptor> overridePds = new Dictionary<string, PropertyDescriptor>();
    
            public PropertyOverridingTypeDescriptor(ICustomTypeDescriptor parent)
                : base(parent)
            { }
    
            public void OverrideProperty(PropertyDescriptor pd)
            {
                overridePds[pd.Name] = pd;
            }
    
            public override object GetPropertyOwner(PropertyDescriptor pd)
            {
                object o = base.GetPropertyOwner(pd);
    
                if (o == null)
                {
                    return this;
                }
    
                return o;
            }
    
            public PropertyDescriptorCollection GetPropertiesImpl(PropertyDescriptorCollection pdc)
            {
                List<PropertyDescriptor> pdl = new List<PropertyDescriptor>(pdc.Count+1);
    
                foreach (PropertyDescriptor pd in pdc)
                {
                    if (overridePds.ContainsKey(pd.Name))
                    {
                        pdl.Add(overridePds[pd.Name]);
                    }
                    else
                    {
                        pdl.Add(pd);
                    }
                }
    
                PropertyDescriptorCollection ret = new PropertyDescriptorCollection(pdl.ToArray());
    
                return ret;
            }
    
            public override PropertyDescriptorCollection GetProperties()
            {
                return GetPropertiesImpl(base.GetProperties());
            }
            public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
            {
                return GetPropertiesImpl(base.GetProperties(attributes));
            }
        }
    

    Few remarks:

    • Constructor takes ICustomTypeDescriptor, no worries here, we can get one for any type or it’s instance with the TypeDescriptor.GetProvider(_settings).GetTypeDescriptor(_settings) where _settings can be either Type or object of that type.
    • OverrideProperty does just what we need, more on it later.

    The other class we need is the TypeDescriptionProvider that will return our custom type descriptor instead of the default one. Here it is:

    public class TypeDescriptorOverridingProvider : TypeDescriptionProvider
        {
            private readonly ICustomTypeDescriptor ctd;
    
            public TypeDescriptorOverridingProvider(ICustomTypeDescriptor ctd)
            {
                this.ctd = ctd;
            }
    
            public override ICustomTypeDescriptor GetTypeDescriptor (Type objectType, object instance)
            {
                return ctd;
            }
        }
    

    Fairly simple: you just supply the type descriptor instance on construction and here you go.

    And finally, processing code. For example, we want all properties ending with ConnectionString in our object (or type) _settings to be editable with the System.Web.UI.Design.ConnectionStringEditor. To achieve that, we can use this code:

    // prepare our property overriding type descriptor
    PropertyOverridingTypeDescriptor ctd = new PropertyOverridingTypeDescriptor(TypeDescriptor.GetProvider(_settings).GetTypeDescriptor(_settings));
    
    // iterate through properies in the supplied object/type
    foreach (PropertyDescriptor pd in TypeDescriptor.GetProperties(_settings))
    {
        // for every property that complies to our criteria
        if (pd.Name.EndsWith("ConnectionString"))
        {
            // we first construct the custom PropertyDescriptor with the TypeDescriptor's
            // built-in capabilities
            PropertyDescriptor pd2 =
                TypeDescriptor.CreateProperty(
                    _settings.GetType(), // or just _settings, if it's already a type
                    pd, // base property descriptor to which we want to add attributes
                        // The PropertyDescriptor which we'll get will just wrap that
                        // base one returning attributes we need.
                    new EditorAttribute( // the attribute in question
                        typeof (System.Web.UI.Design.ConnectionStringEditor),
                        typeof (System.Drawing.Design.UITypeEditor)
                    )
                    // this method really can take as many attributes as you like,
                    // not just one
                );
    
            // and then we tell our new PropertyOverridingTypeDescriptor to override that property
            ctd.OverrideProperty(pd2);
        }
    }
    
    // then we add new descriptor provider that will return our descriptor instead of default
    TypeDescriptor.AddProvider(new TypeDescriptorOverridingProvider(ctd), _settings);
    

    That’s it, now all properties ending with ConnectionString will be editable through ConnectionStringEditor.

    As you can see, we just override some functionality of the default implementation every time, so the system should be fairly stable and behave as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Which browsers (and versions) do not support custom attributes? I want to add some
I am creating a custom control and i want to add some properties in
I want to add some custom roads using google maps api (i.e. off-road routes,
I want to add some values in arraylist but at random index. Is this
I want to add some custom HTML between the buttons on a jQuery dialog
I want to add some custom javascript functions to my design document, I can't
I want to add some custom fields to add new user in Wordpress .
I have GridEx object on my form and... I want to add some items
I am facing an issue in Magento. I want to add some custom fields
I have a view that I want to add some custom drawing to. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.