Class Cs.ListPattern

java.lang.Object
org.openrewrite.csharp.tree.Cs.ListPattern
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.ListPattern extends Object implements Cs.Pattern
Represents a C# list pattern that matches elements in a list or array against a sequence of patterns.

For example:

     // Simple list patterns
     if (array is [1, 2, 3] lst)
     if (list is [1, _, 3])

     // With designation
     if (points is [(0, 0), (1, 1)] coords)

     // With slices
     if (numbers is [1, .., 5] sequence)
     if (values is [1, 2, .., 8, 9] arr)

     // With subpatterns
     if (points is [(0, 0), (1, 1)])

     // With type patterns
     if (list is [int i, string s] result)

     // In switch expressions
     return array switch {
         [var first, _] arr => arr.Length,
         [1, 2, ..] seq => "starts with 1,2",
         [] empty => "empty",
         _ => "other"
     };

     // With length patterns
     if (array is [> 0, <= 10] valid)
 
  • Constructor Details

    • ListPattern

      public ListPattern()
  • Method Details

    • getPatterns

      public List<Cs.Pattern> getPatterns()
    • withPatterns

      public Cs.ListPattern withPatterns(List<Cs.Pattern> patterns)
    • getType

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

      public Cs.ListPattern 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
    • getPadding

      public Cs.ListPattern.Padding getPadding()