Open AzaleaHarper opened 2 years ago
@sgjsakura we found the simpler fix which is to change this line
from:
var result = actualValues.Aggregate(0, (current, value) => current | (int)value);
to:
var result = actualValues.Aggregate(0UL, (current, value) => current | Convert.ToUInt64(value));
In our project we use enums that are inheriting from
byte
, but theFlagsEnumModelBinder
andFlagsEnumModelBinderProvider
only handle the case where the enum is of type int.I've managed to get it to work as intended by checking the underlying enum type and then returning a model binder that matches that type.
FlagsEnumModelBinderProvider
And then in each ModelBinder on the aggregate I change the cast to the expected type.
byte
var result = actualValues.Aggregate(0, (current, value) => (byte)(current | (byte)value));
short
var result = actualValues.Aggregate(0, (current, value) => (short)((short)current | (short)value));
long
var result = actualValues.Aggregate((long)0, (current, value) => (current | (long)value));