ardalis / ardalis/SmartEnum

GetFlagEnumValues is not safe to use

Open
#387 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
2.4k
Forks
184
PR merge metrics
No merged PRs in 30d

Description

It declares to return `IEnumerable`, so I except it is never null (https://rules.sonarsource.com/csharp/RSPEC-1168).

But `MyEnum.FromValue(0)` returns null.

```
public sealed class MyEnum : SmartFlagEnum
{
public static readonly MyEnum X= new MyEnum(1);
public static readonly MyEnum Y= new MyEnum(2);

private MyEnum (int value, [CallerMemberName] string name = null)
: base(name, value)
{
}
}
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating GetFlagEnumValues and the FromValue(0) path described in the issue. Compare their behavior with the RSPEC-1168 non-null expectation; the issue is done when the reported null result is resolved and the method's IEnumerable contract is upheld.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.