XamarinCommunityToolkit icon indicating copy to clipboard operation
XamarinCommunityToolkit copied to clipboard

[Bug] EnumToBoolConverter for Flags Enum

Open MAVREE opened this issue 1 year ago • 0 comments

Description

Please tell me if I'm completely wrong, but shouldn't the method .HasFlag be called on the valueToCheck instead of the referenceEnumValue?

What I mean is, at the moment if the variable I'm binding to is a Flag attribute with values: MyFlagEnum.A | MyFlagEnum.B | MyFlagEnum.C and I put as TrueValue in the converter MyFlagEnum.B only, the method call checks if "MyFlagEnum.B" has the flag "MyFlagEnum.A | MyFlagEnum.B | MyFlagEnum.C" which obviously returns false.

https://github.com/xamarin/XamarinCommunityToolkit/blob/5a6062f3c3543acda3c36ca4683cd8fc7fe86ba7/src/CommunityToolkit/Xamarin.CommunityToolkit/Converters/EnumToBoolConverter.shared.cs#L54-L55

  • Version with issue: 2.0.6

Workaround

As a workaround I wrote a custom EnumToBoolConverter that simply calls the HasFlag() method on the valueToCheck variable instead of the referenceEnumValue

MAVREE avatar Oct 25 '23 10:10 MAVREE