I’ve got an enum of types of data that might be shown in a .NET Forms control and I want to provide an interface for consumers of the control to filter some of the types (set some of the flags). A bit field seems the logical way to do this, unfortunately, the enum starts at 0 rather than 1 (0, 1, 2, 4, 8, …) and can’t be changed.
How can I expose this set of flags so that it can be easily configured programmatically or through the Visual Studio designer?
You would need to write a
UITypeEditorto do the work, and associate it with the property via[EditorAttribute].edit now with example – a fairly long one, I’m afraid – but most of the code can be shared between types, fortunately.
You can’t use a single composite enum value because of the zero – so here I’m using a
HashSet<T>to hold the selected enums – fairly easy to re-work toList<T>if you have .NET 2.0/3.0, though.