Json2CSharp / Json2CSharpCodeGenerator

Microsoft Reciprocal License
292 stars 81 forks source link

Records #70

Closed TonyValenti closed 2 years ago

TonyValenti commented 2 years ago

@HoLLy-HaCKeR - Thanks for doing the new commit! I was wondering if you could add a few new features. Here's an example of how I'd like to see classes generated. I've put comments in-line.

    public record Person  //This is a record not a class
    {
        //long instead of int is used.  Also, the property is init instead of set.
        public long Id { get; init; } 

        //Because the value can be null, string? is nullable-annotated.
        public string? Etag { get; init; } 

        //Because Name is required, it is defaulted to string.Empty;
        public string Name { get; init; } = string.Empty; 

        //Using a DateTimeOffset instead of DateTime
        public DateTimeOffset received_at { get; init; } 

        //The list is an immutable list and has a default value provided.
        public ImmutableList<Person> Children {get; init;} = ImmutableList<Person>.Empty;

        //The list is an immutable list, has no default value, and is nullable-annotated.
        public ImmutableList<Person>? Parents {get; init;}
    }
Json2CSharp commented 2 years ago

On what basis do all of these conditions need to happen, I feel like this is a very specific case to issue a code change

Json2CSharp commented 2 years ago

Didn't hear from the op, I will close this issue. Feel free to reopen with more details please