Skip to content

Extended property patterns C# 10.0

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.

This syntax simplifies the syntax by allowing dot notation to match the property directly.

Code

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

More information