Remove C# attribute of a property dynamically

后端 未结 5 1692
不思量自难忘°
不思量自难忘° 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:41

    The CodingLight.com blog moved to blogspot (the above link is broken). See http://codinglight.blogspot.com/2008/10/changing-attribute-parameters-at.html.

    Moreover, SysAdmin's followup did not mention the [RefreshProperties(RefreshProperties.All)] attribute that seems to be necessary for an actually-working solution.

    Finally, I believe that even David Morton (author of the quoted article) missed one very important thing: if the class (ContactInfo, in SysAdmin's followup example) does not have at least one property with the [ReadOnly] attribute defined at compile time, then when the "isReadOnly" FieldInfo is set to true at runtime the result is that the whole class turns read-only.

提交回复
热议问题