Remove C# attribute of a property dynamically

后端 未结 5 1691
不思量自难忘°
不思量自难忘° 2020-11-30 09:18

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

class ContactInfo
{
    [ReadOnly(true)]
    [Category(\"Contact Info\")]
    public string Mobile {          


        
5条回答
  •  感动是毒
    2020-11-30 09:40

    You can not remove the attribute at runtime, but you can use reflection to change the ReadOnly attribute's ReadOnly private backing field to False. Making it the equivalent of [ReadOnly(false)]

    See this article for details:

    http://codinglight.blogspot.com/2008/10/changing-attribute-parameters-at.html

    Edit: fixed link

提交回复
热议问题