feat: add null-safe TryFromValue signature and tests - #577
teesofttech wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the SmartEnum<TEnum, TValue>.TryFromValue API to be null-safe and adds unit tests covering TryFromValue behavior for both int-backed and string-backed smart enums.
Changes:
- Update
TryFromValueto accept nullable input (TValue?) and avoid exceptions on null input. - Add new unit tests validating
TryFromValuesuccess/failure cases for value and string enums.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/SmartEnum/SmartEnum.cs |
Adjusts TryFromValue signature/implementation to handle nullable inputs. |
test/SmartEnum.UnitTests/SmartEnumTryFromValue.cs |
Adds tests exercising TryFromValue behavior for matching/non-matching values and null string input. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@ardalis Can you review this PR please |
|
Looks like it doesn't work with netstandard and has some other things needed to change based on the broken build: Warning: /home/runner/work/SmartEnum/SmartEnum/test/SmartEnum.SystemTextJson.UnitTests/SmartEnumNameConverterTests.cs(112,9): warning S125: Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125) [/home/runner/work/SmartEnum/SmartEnum/test/SmartEnum.SystemTextJson.UnitTests/SmartEnum.SystemTextJson.UnitTests.csproj::TargetFramework=net8.0] |
Looking into this now |

feat: add null-safe TryFromValue signature and tests