All rules
IDE0170Language rules (pattern matching preferences)
Simplify property pattern
Simplify property pattern
Microsoft docsDescription
This style rule flags the use of a nested pattern in a property pattern. A nested pattern can be simplified to use an extended property pattern in which property subpatterns are used to reference nested members. Extended property patterns improve code readability.
Example
public record Point(int X, int Y);
public record Segment(Point Start, Point End);
// Violates IDE0170.
static bool IsEndOnXAxis(Segment segment) =>
segment is { Start: { Y: 0 } } or { End: { Y: 0 } };
// Fixed code.
static bool IsEndOnXAxis(Segment segment) =>
segment is { Start.Y: 0 } or { End.Y: 0 };Configurable options
Vote for the value each option should take in the generated .editorconfig.
csharp_style_prefer_extended_property_pattern default:
trueYour vote
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0