I am refactoring some code for several enum collections that support the [Flags] attribute.
I am trying to come up with a generic class that allows for common methods (adding, removing and checking enums exist in the collection etc).
I began with this code:
public class EnumFlags
{
protected T collection;
public void Add(T value)
{
this.collection = this.collection | value;
}
}
However, I cannot use the | operator on type T. I cannot add a constraint for T to be an enum (where T : Enum
is not allowed).
Any ideas to approaching this problem?
No comments:
Post a Comment