0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

.NET 5 RC 1 以降なら Positional Record Type でも属性が使える

Last updated at Posted at 2020-11-02

これまでは Positional Record の各フィールドに属性を付与することができませんでしたが、.NET 5 RC 1 から可能になりました。
これで、各フィールドの入力検証などをおこなうことができるようになります。

// .NET 5 RC 1 以降

using System.Text.RegularExpressions;

record Age([Range(0, 200)] int Value);

record NamePhonetic(
    [RegularExpression(@"^\p{IsKatakana}*$"), ErrorMessage = "Must only Katakana."]
    string LastName,
    [RegularExpression(@"^\p{IsKatakana}*$"), ErrorMessage = "Must only Katakana."]
    string FirstName);

おわり。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?