Skip to content

Conversation

@paulhazen
Copy link
Contributor

This PR improves the way in which a number value is cast into an enum type via EnumUtility.

Currently, when an attempt is made to convert a value that does not correspond to a named value within the enum, the lowest value in the enum is selected.

This change checks not just for if the value is out of range by being too low, but also checking for if the value is out of range by being too high. If either is the case, then instead of selecting the highest or lowest value accordingly, a value of 0 is selected.

Despite not necessarily being a named value within an enum, 0 is always a valid value for any enum, and is used to indicate a value that is not set.

#EOS-2381

@paulhazen paulhazen added enhancement New feature or request fix PR contains a fix. tracked This issue has a corresponding task in our internal bug tracking system labels Jan 29, 2025
@paulhazen paulhazen self-assigned this Jan 29, 2025
@paulhazen paulhazen changed the title Fix/smarter enum casting fix: Smarter Enum Conversion Jan 29, 2025
@WispyMouse WispyMouse changed the base branch from development to release-3.3.6 January 29, 2025 20:24
@WispyMouse
Copy link
Contributor

Retargeted to release-3.3.6.

Copy link
Contributor

@WispyMouse WispyMouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran the ListOfStringsToEnumConverterTests set, which seem relevant here.

ListOfStringsToEnumConverterTestClass_ReadJson_InvalidTokenType_ThrowsException no longer throws an exception, instead setting the value to 0. Should we remove the test?

…um_EvaluatesToZero` Test

Adds a test that ensures Flags can have their value set to 0, even if the Enum does not contain 0 as an explicit value.
Copy link
Contributor

@WispyMouse WispyMouse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test for Flags being set to 0. This looks good to me and functions correctly.

@paulhazen paulhazen merged commit 101c5ec into release-3.3.6 Jan 31, 2025
@EpicCliffHudson EpicCliffHudson deleted the fix/smarter-enum-casting branch September 23, 2025 03:31
@EpicCliffHudson EpicCliffHudson restored the fix/smarter-enum-casting branch September 23, 2025 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request fix PR contains a fix. tracked This issue has a corresponding task in our internal bug tracking system

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants