Skip to content

Extended property patterns C# 10.0code reductionreadability

Allow property sub-patterns to reference nested members.

Property patterns C# 8.0 are a very powerful feature, however matching properties within nested objects was verbose.

C# 10.0 simplifies this by allowing dot notation to match nested properties directly.

Code ​

csharp
return analysis switch
{
    { MatchedRule.Action: "ignore" } => Action.Ignore,
    _ => Action.Block,
};
csharp
return analysis switch
{
    { MatchedRule: { Action: "ignore" } } => Action.Ignore,
    _ => Action.Block,
};

Notes ​

  • Reduces the need for deeply nested { Prop: { SubProp: value } } syntax
  • Works with any pattern, not just constants, so you can use relational patterns, var captures, etc.

More information ​

Powered by Intracia