Class Cs.RecursivePattern

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

public static final class Cs.RecursivePattern extends Object implements Cs.Pattern
Represents a C# recursive pattern that can match nested object structures, including property patterns and positional patterns.

For example:

     // Simple property pattern
     if (obj is { Name: "test", Age: > 18 })

     // With type pattern
     if (obj is Person { Name: "test" } p)

     // With nested patterns
     if (obj is { Address: { City: "NY" } })

     // Positional patterns (deconstructions)
     if (point is (int x, int y) { x: > 0, y: > 0 })

     // With variable designation
     if (obj is { Id: int id, Name: string name } result)

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

    • RecursivePattern

      public RecursivePattern()
  • Method Details

    • getType

      public org.openrewrite.java.tree.JavaType getType()
      Specified by:
      getType in interface org.openrewrite.java.tree.Expression
    • withType

      public Cs.RecursivePattern withType(@Nullable org.openrewrite.java.tree.JavaType type)
      Specified by:
      withType in interface org.openrewrite.java.tree.Expression
    • acceptCSharp

      public <P> org.openrewrite.java.tree.J acceptCSharp(CSharpVisitor<P> v, P p)
      Specified by:
      acceptCSharp in interface Cs
    • getCoordinates

      public org.openrewrite.java.tree.CoordinateBuilder.Expression getCoordinates()
      Specified by:
      getCoordinates in interface org.openrewrite.java.tree.Expression