question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[System.Text.Json] Generated enum values are Pascal-case

See original GitHub issue

Schema:

enum SnakeEnum {
    PIE_CHARMER,
    VS_CODE,
}

Generates:

public enum SnakeEnum 
{
    [EnumMember(Value = "PIE_CHARMER")] PieCharmer,
    [EnumMember(Value = "VS_CODE")] VsCode
}

This is fine if you are using a Json library that supports the EnumMember attribute. Unfortunately System.Text.Json does not. Propose:

  • Command-line option --enumTypeNaming: Either CSharp (default, current) or UpperSnakeCase

I’ve started work on this and will submit a PR later today if it’s desired.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
nerocuicommented, Jun 6, 2022

@HaikuJock thank you for explaining. Sorry I saw you had contribution and thought you were the owner.

0reactions
Husqvikcommented, Jun 6, 2022

published a new version 0.9.9

Use

EnumValueNaming = EnumValueNamingOption.Original if generating from code

--enumValueNaming Original if using console app/tool

<GraphQlClientGenerator_EnumValueNaming>Original</GraphQlClientGenerator_EnumValueNaming> if using source generator

Read more comments on GitHub >

github_iconTop Results From Across the Web

System.Text.Json: How to serialize a individual enum as ...
System.Text.Json default to number the enum serialization. In my case I need the string for that in the Startup.cs I add a converter...
Read more >
How to enable case-insensitive property name matching ...
In this article, you will learn how to enable case-insensitive property name matching with the System.Text.Json namespace.
Read more >
Serializing enums as strings using System.Text.Json library ...
While serializing an object into JSON using the new library we can control various options such as casing, indentation, etc, but one notable ......
Read more >
How to Serialize Enum to a String in C# - Code Maze
In this article, we will demonstrate different ways of how to serialize enum to string in C# with detailed explanation and examples.
Read more >
How to customize property names and values with System. ...
Learn how to customize property names and values when serializing with System.Text.Json in .NET.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found