Class Cs.IsPattern

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

public static final class Cs.IsPattern extends Object implements Cs, org.openrewrite.java.tree.Expression
Represents a C# is pattern expression that performs pattern matching. The expression consists of a value to test, followed by the 'is' keyword and a pattern.

For example:

     // Type pattern
     if (obj is string)

     // Type pattern with declaration
     if (obj is string str)

     // Constant pattern
     if (number is 0)

     // Property pattern
     if (person is { Name: "John", Age: 25 })

     // Relational pattern
     if (number is > 0)

     // Var pattern
     if (expr is var result)

     // List pattern
     if (list is [1, 2, 3])
 
  • Constructor Details

    • IsPattern

      public IsPattern()
  • Method Details

    • getPattern

      public Cs.Pattern getPattern()
    • withPattern

      public Cs.IsPattern withPattern(Cs.Pattern pattern)
    • acceptCSharp

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

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

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

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

      public Cs.IsPattern.Padding getPadding()