- public record User(string Name,DateTime DOB);
Now let's consider a situation where you want to serialize the
User record, as shown in the following.- { "User": "Anu Viswan", "DateOfBirth": "2020-11-20T00:00:00" }
- public record User
- {
- [JsonProperty("User")]
- public string Name{get;init;}
- [JsonProperty("DateOfBirth")]
- public DateTime Dob{get;init;}
- }
- // This is wrong - it sets Attributes to the constructor parameter
- public record User([JsonProperty("User")]string Name,[JsonProperty("DateOfBirth")]DateTime DOB);

Join the conversation! Your thoughts help the community grow.