FromEnumString return unexpected result if input is invalid
Open
Nobody has claimed this yet.
bug
- Dominant language
- C#
- Stars
- 0
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
FirstOrDefault return not null, but default value, so method never throw exeption:
public static T FromEnumString<T>(string value) where T : struct, Enum
{
value.ThrowIfNull();
var reflectionAttributeFinder = new ReflectionAttributeFinder();
IReadOnlyDictionary<T, EnumStringValueAttribute> enumStrings = reflectionAttributeFinder.GetAttributesFromEnumValues<EnumStringValueAttribute, T>();
KeyValuePair<T, EnumStringValueAttribute>? selectedEnumValue = enumStrings.FirstOrDefault(p => p.Value.StringValue == value);
if (selectedEnumValue is null)
throw new ReflectionException($"Cannot find enum values associated to string {value} in {typeof(T).Name}");
return selectedEnumValue.Value.Key;
}
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the FromEnumString entry point shown in the issue and inspect how FirstOrDefault is checked when no enum value matches. Add coverage for an invalid string and verify that it throws ReflectionException, while existing valid-value behavior remains unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 40/100