Skip to content

Extended property patterns C# 10.0code reductionreadability

Allow property sub-patterns to reference nested members.

Pattern matching C# 7.0 is a very powerful feature however matching properties within objects was verbose.

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

Code

C#
return analysis switch
{
    { MatchedRule.Action: "ignore" } => Action.Ignore,
    _ => Action.Block,
};
C#
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 — you can use relational patterns, var captures, etc.

More information