R – 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
     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.

Best Solution

You can implement a custom type descriptor - which intercepts the the attribute on the way to whatever is using it. Thus having an effect which looks like the attribute is changing.

See - Part 1, Part2