I have enum lets say for example:
public enum Color
{
red,
green,
blue
}
And have two classes. which have property of enum.
public class ClassA
{
public Color Color{get;set;}
}
public class ClassB
{
[InvisibleFlag(Color.red)] // I want something like that
public Color Color{get;set;}
}
Now in Windows Forms Designer, I want to hide the red flag only from the Color enumeration for ClassB only.
I know that I can create a separated enum. but why duplicate values? I gave a simple example only.
Something I guess might help for superior who can help me at it.
Descriptor API. which I hate. ;(
Maybe something like TypeDescriptor.AddAttributes(object, new BrowsableAttribute(false));
This answer will not work in this case. I don't want to apply Browsable
attribute to the enum flags because it hides that flag in property grid for all classes. I want to be able to hide specific enum values for specific classes only, not for all classes.
GetStandardValues()
method override, you can filter the Enum values to return a new collection that excludes the Value specified by theInvisibleFlag
attribute. You also have to overrideCanConvertFrom
andConvertFrom
, to convert the string representation of the Enum to an Enum value. You also need to create theInvisibleFlag
custom attribute, with two constructors: one that accepts the enum type and one that accepts a string. A[DefaultValue(...)]
attribute should be used, to avoid a default assignment to an excluded enum value. – Phillipsred
value from being an option in the property grid for the class when shown in the Designer. – Barthold