rksoftware

Visual Studio とか C# とかが好きです

拡張プロパティのパターン

■ C# 10.0 での新機能

・拡張プロパティのパターン (Extended property patterns)
  https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/extended-property-patterns
 プロパティの中のオブジェクトのプロパティをシンプルな記述でパターンマッチングできる。

SampleA a = new();

// プロパティの中のプロパティをシンプルに書ける
if (a is SampleA { PropertyA.PropertyB: 1 })
{
}

// 構造体定義
struct SampleA
{
    public SampleB PropertyA { get; set; }
}

struct SampleB
{
    public int PropertyB { get; set; }

}