Class Cs.BinaryPattern

java.lang.Object
org.openrewrite.csharp.tree.Cs.BinaryPattern
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.BinaryPattern extends Object implements Cs.Pattern
Represents a C# binary pattern that combines two patterns with a logical operator. The binary pattern is used in pattern matching to create compound pattern tests.

For example:

     // Using 'and' to combine patterns
     if (obj is string { Length: > 0 } and not null)

     // Using 'or' to combine patterns
     if (number is > 0 or < -10)

     // Combining type patterns
     if (obj is IList and not string)

     // Complex combinations
     if (value is >= 0 and <= 100)

     // Multiple binary patterns
     if (obj is IEnumerable and not string and not int[])

     // In switch expressions
     return size switch {
         < 0 or > 100 => "Invalid",
         >= 0 and <= 50 => "Small",
         _ => "Large"
     };
 
  • Constructor Details

    • BinaryPattern

      public BinaryPattern()
  • Method Details

    • getOperator

      public Cs.BinaryPattern.OperatorType getOperator()
    • withOperator

      public Cs.BinaryPattern withOperator(Cs.BinaryPattern.OperatorType operator)
    • getType

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

      public Cs.BinaryPattern 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.BinaryPattern.Padding getPadding()