Class Cs.ConstantPattern

java.lang.Object
org.openrewrite.csharp.tree.Cs.ConstantPattern
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.ConstantPattern extends Object implements Cs.Pattern
Represents a C# constant pattern that matches against literal values or constant expressions.

For example:

     // Literal constant patterns
     if (obj is null)
     if (number is 42)
     if (flag is true)
     if (ch is 'A')
     if (str is "hello")

     // Constant expressions
     const int MAX = 100;
     if (value is MAX)

     // In switch expressions
     return value switch {
         null => "undefined",
         0 => "zero",
         1 => "one",
         _ => "other"
     };

     // With other pattern combinations
     if (str is not null and "example")

     // Enum constant patterns
     if (day is DayOfWeek.Sunday)
 
  • Constructor Details

    • ConstantPattern

      public ConstantPattern()
  • Method Details

    • getType

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

      public Cs.ConstantPattern 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