Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SmartFlagEnum does not support values larger than int.MaxValue #408

Open
makercob opened this issue Jul 16, 2023 · 1 comment
Open

SmartFlagEnum does not support values larger than int.MaxValue #408

makercob opened this issue Jul 16, 2023 · 1 comment

Comments

@makercob
Copy link

Given a enum class as follow:

[AllowUnsafeFlagEnumValues]
public sealed class FooEnum : SmartFlagEnum<FooEnum, uint> {
    public static readonly FooEnum Flag32 = new(nameof(Flag32), 0x01u << 31);

    public static readonly FooEnum Flag1 = new(nameof(Flag1), 0x01u << 0);

    FooEnum(string name, uint value) : base(name, value) { }
}

The following code

FooEnum.FromValue(0b_0000_0001u)

throws exception:

Unhandled exception. System.OverflowException: Value was either too large or too small for an Int32.
   at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, ReadOnlySpan`1 value, TypeCode type)
   at System.Int32.Parse(String s)
   at Ardalis.SmartEnum.SmartFlagEngine`2.HighestFlagValue(IReadOnlyList`1 enumList)
   at Ardalis.SmartEnum.SmartFlagEngine`2.CalculateHighestAllowedFlagValue(List`1 inputEnumList)
   at Ardalis.SmartEnum.SmartFlagEngine`2.GetFlagEnumValues(TValue value, IEnumerable`1 allEnumList)
   at Ardalis.SmartEnum.SmartFlagEnum`2.FromValue(TValue value)
@ardalis
Copy link
Owner

ardalis commented Jan 16, 2024

Correct. Is this an issue for someone? How many flags do you expect to have?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants