Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting value of BrowsableAttribute at runtime

I wanted to set a value of BrowsableAttribute for some of MyClass instance's properties at runtime:

 public class MyClass
{
     [Browsable(true)]
     public int P1 { get; set } 
     ...
}

Please advise how it can be done as well as how to add BrowsableAttribute to a MyClass instance's property at runtime if this attribute doesn't exist.

like image 835
ShamilS Avatar asked Jul 02 '26 09:07

ShamilS


1 Answers

You can't - unless you intercept loading the assembly. The attributes are stored in metadata, and loaded with the assembly, and attributes should generally be immutable (as BrowsableAttribute is).

Basically attributes aren't meant to be modified at execution time.

like image 73
Jon Skeet Avatar answered Jul 05 '26 01:07

Jon Skeet