views:

56

answers:

2

Depending on a preprocessor directive, I want to set all properties in a class to EditorBrowsableAttribute.Never.

I thought about creating a custom attribute, derived from EditorBrowsableAttribute, but unfortunately that class is sealed.

I've had a look at ICustomTypeDescriptor, but in the GetProperties method, I can get hold of each property descriptor, but the attributes collection is readonly.

Any ideas?

A: 

Have a look at this article and see if does what you are looking for.

Khadaji
+3  A: 

One approach is to explicitly use the #if syntax

#if SOMECONDITION
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
public int SomeProperty { get; set; }
JaredPar
I know I can do that, but I'm trying to avoid doing it for every single member. It also looks messy, which is why it would have been nice to be able to create a class derived from EditorBrowsableAttribute, containing the #if statement. I'd then decorate each member with the custom attribute.
Jules