-
Currently (.NET 5 rc2), the annotations on the parameters of the record's primary constructor only affect the constructor parameters but not the property. The decompilation of the following code public sealed record Email([EmailAddress] string Address) {} is public sealed class Email : IContactInfo, IEquatable<Email>
{
public string Address { get; init; }
public Email([EmailAddress] string Address)
{
this.Address = Address;
}
// ...
} which is not what I expect. I want something like public sealed class EmailRecord : IContactInfo, IEquatable<EmailRecord>
{
[EmailAddress]
public string Address { get; }
public EmailRecord(string address)
{
Address = address;
}
// ...
} It's very useful when working with data validation in Model. I want an option to attach annotation on the property, or just attach the annotations on both constructor parameter and property. |
Beta Was this translation helpful? Give feedback.
Answered by
svick
Oct 24, 2020
Replies: 1 comment
-
public sealed record Email([property: EmailAddress] string Address) {} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Jason5Lee
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do it like this: