A real-life example:
This record
public record GetAccountHolderParameters([property: JsonProperty("accountHolderCode")] string Code, [property: JsonProperty("showDetails")] bool ShowDetails);
or this preferred syntax which is better to read
public record GetAccountHolderParameters(
[property: JsonProperty("accountHolderCode")] string Code,
[property: JsonProperty("showDetails")] bool ShowDetails
);
is equivalent to
public class GetAccountHolderParameters
{
[JsonProperty(PropertyName = "accountHolderCode")]
public string Code { get; set; }
[JsonProperty(PropertyName = "showDetails")]
public bool ShowDetails { get; set; }
}
Note about ASP.NET Core request parameters
You can't apply validation attributes [property: ... ]
to your request parameters, see this question.
You will receive InvalidOperationException(...)
.
For details, see this issue.
record
. – Revolutionary