Repository navigation
Added Enum Converter to Respect EnumMemberAttribute - #1132
Merged
Merged
Conversation
pr-comment: Run #178
🎉 All tests passed!Github Test Reporter by CTRF 💚 🔄 This comment has been updated |
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The replacement enum converter breaks enum-keyed dictionaries, mishandles numeric bounds, and changes unnamed enum values from numbers to strings, regressing supported IPC and HostHook payloads.
3 open issues
What changed in this PR
This PR updates ElectronNET’s shared JSON serialization to honor custom enum names, addressing values such as macOS vibrancy’s under-window.
Changes:
- Adds an enum converter that respects
EnumMemberandJsonPropertyNameattributes, with camel-case fallback. - Registers the converter in the shared serializer options.
- Adds tests for annotated names, nested options, deserialization, numeric inputs, and nullable enums.
| File | Description |
|---|---|
src/ElectronNET.IntegrationTests/Tests/EnumSerializationTests.cs |
Adds enum serialization and deserialization tests. |
src/ElectronNET.API/Serialization/EnumMemberStringEnumConverter.cs |
Implements attribute-aware enum conversion. |
src/ElectronNET.API/Serialization/ElectronJson.cs |
Replaces the built-in converter with the custom converter. |
Review effort: Balanced
Refactor enum serialization methods to improve handling of numeric values and property names. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

As the title says, the current enum serialization completely ignores the
EnumMemberattribute which causes all enum members that have different string representations than their enum label to serialize incorrectly. I noticed this issue when investigating the vibrancy option on macOS (specificallyunder-window). I added a custom converter that resolves theEnumMemberattribute on enum fields.I suspect this was caused by moving from
Newtonsoft.JsontoSystem.Text.Jsonwhich ignores theEnumMemberattribute (Newtonsoft.Jsonrespected that attribute).System.Text.Jsonhas an equivalentJsonStringEnumMemberNameattribute but that only ships withnet9.0or newer.