Remove C# attribute of a property dynamically

Posted by SysAdmin on Stack Overflow See other posts from Stack Overflow or by SysAdmin
Published on 2010-03-20T13:11:37Z Indexed on 2010/03/20 13:21 UTC
Read the original article Hit count: 211

Filed under:
|
|

Hi, I have a class with a set of properties As given below.

class ContactInfo
{
        [ReadOnly(true)]
        [Category("Contact Info")]
        public string Mobile { get; set; }

        [Category("Contact Info")]
        public string Name{ get; set; }
}

The objects of this class is being assigned to a property grid, so that the users can update an existing contact. you can see that Mobile is marked as ReadOnly.

But, when I want to add an entirely new Contact, I would want the users to be able to edit the contact Mobile also. For that I need to remove the Readonly property dynamically from the Type, before assigning the object to the property grid. Is it possible?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET