Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] EnumToBoolConverter for Flags Enum #1992

Open
MAVREE opened this issue Oct 25, 2023 · 0 comments
Open

[Bug] EnumToBoolConverter for Flags Enum #1992

MAVREE opened this issue Oct 25, 2023 · 0 comments
Labels
bug Something isn't working. Breaky break. maui-compat

Comments

@MAVREE
Copy link

MAVREE commented Oct 25, 2023

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.

if (valueToCheckType.GetTypeInfo().GetCustomAttribute<FlagsAttribute>() != null)
return referenceEnumValue.HasFlag(valueToCheck);

  • 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 MAVREE added bug Something isn't working. Breaky break. maui-compat labels Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working. Breaky break. maui-compat
Projects
None yet
Development

No branches or pull requests

1 participant