Class Cs.Subpattern

java.lang.Object
org.openrewrite.csharp.tree.Cs.Subpattern
All Implemented Interfaces:
Cs, org.openrewrite.java.tree.J, org.openrewrite.Tree
Enclosing interface:
Cs

public static final class Cs.Subpattern extends Object implements Cs
Represents a subpattern in C# pattern matching, which can appear in property patterns or positional patterns. Each subpattern consists of an optional name with a corresponding pattern.

For example:

     // In property patterns
     if (obj is { Name: "test", Age: > 18 })
                  ^^^^^^^^^^^^  ^^^^^^^^^

     // In positional patterns
     if (point is (x: > 0, y: > 0))
                   ^^^^^^  ^^^^^^

     // With variable declarations
     if (person is { Id: var id, Name: string name })
                     ^^^^^^^^^^  ^^^^^^^^^^^^^^^^^

     // Nested patterns
     if (obj is { Address: { City: "NY" } })
                  ^^^^^^^^^^^^^^^^^^^^^^^

     // In switch expressions
     return shape switch {
         { Radius: var r } => Math.PI * r * r,
           ^^^^^^^^^^^
         { Width: var w, Height: var h } => w * h,
           ^^^^^^^^^^^^  ^^^^^^^^^^^^^
         _ => 0
     };