Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better Options #102

Open
TonyValenti opened this issue May 14, 2023 · 0 comments
Open

Better Options #102

TonyValenti opened this issue May 14, 2023 · 0 comments

Comments

@TonyValenti
Copy link

Hi All,
I would like the JSON that is generated to be different than what is currently output.
This ChatGPT prompt demonstrates an example of input and desired output:

Input

Generate C-sharp classes from this json.
Use nullable reference types, get and init accessors, and immutable lists.
Do not use primary constructors.
Replace the word class with record.
Use long instead of int.
Use DateTimeOffset instead of DateTime.
Append "Json" to the end of each name.


{"widget": {
    "debug": "on",
   "date": "2023-02-01",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
   
    "images": [{ 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    }, { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    }]
}}  

Output

public record WidgetJson
{
    public string? Debug { get; init; }
    public DateTimeOffset? Date { get; init; }
    public WindowJson? Window { get; init; }
    public ImmutableList<ImageJson>? Images { get; init; }
}

public record WindowJson
{
    public string? Title { get; init; }
    public string? Name { get; init; }
    public long Width { get; init; }
    public long Height { get; init; }
}

public record ImageJson
{
    public string? Src { get; init; }
    public string? Name { get; init; }
    public long HOffset { get; init; }
    public long VOffset { get; init; }
    public string? Alignment { get; init; }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant