Reputation: 4339
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?
Upvotes: 3
Views: 1002
Reputation: 4339
I happened across this issue again recently and this time the answer came to me very quickly; simply set up a couple of constants:
Friend Class CompilerUtils
#If HideCode Then
Public Const Browsable As EditorBrowsableState = EditorBrowsableState.Never
Public Const BrowsableAdvanced As EditorBrowsableState = EditorBrowsableState.Never
#Else
Public Const Browsable As EditorBrowsableState = EditorBrowsableState.Always
Public Const BrowsableAdvanced As EditorBrowsableState = EditorBrowsableState.Advanced
#End If
End Class
Then in your code, decorate a member like so:
<EditorBrowsable(CompilerUtils.Browsable)> _
<EditorBrowsable(CompilerUtils.BrowsableAdvanced)> _
Upvotes: 1
Reputation: 754893
One approach is to explicitly use the #if
syntax
#if SOMECONDITION
[EditorBrowsable(EditorBrowsableState.Never)]
#endif
public int SomeProperty { get; set; }
Upvotes: 3