ReSharper 2024.1 Help

Code Inspection: Merge nested property patterns

Category

Language Usage Opportunities

ID

MergeNestedPropertyPatterns

EditorConfig

resharper_merge_nested_property_patterns_highlighting

Default severity

Suggestion

Language

C#

Requires SWA

No

C# 10 simplifies the pattern matching syntax with dotted access instead of object pattern nesting. ReSharper detects such places in your code and suggests the corresponding quick-fix (Alt+Enter):

public class UserTest { public UserTest() { var user = new User(); // Merge nested property patterns if (user is { Tags: { Count: 0 } }) Console.WriteLine("do something"); } }
public class UserTest { public UserTest() { var user = new User(); if (user is { Tags.Count: 0}) Console.WriteLine("do something"); } }
public class User { public List<string> Tags { get; } = new(); }
Last modified: 15 April 2024