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,
varcaptures, etc.