Given the enum
:
[Flags]
public enum mytest
{
a = 1,
b = 2,
c = 4
}
I\'ve come up with two ways to represent all va
For a generic method, use Linq's Enumerable.Aggregate extension method;
var flags = Enum.GetValues(typeof(mytest))
.Cast()
.Aggregate(0, (s, f) => s | f);
Or in a wrapper method
TEnum GetAll() where TEnum : struct
{
return (TEnum) (object)
Enum.GetValues(typeof(TEnum))
.Cast()
.Aggregate(0, (s, f) => s | f);
}
full credit for this double-cast trick goes to @millimoose