Class Cs.SwitchExpression

java.lang.Object
org.openrewrite.csharp.tree.Cs.SwitchExpression
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.SwitchExpression extends Object implements Cs, org.openrewrite.java.tree.Expression
Represents a C# switch expression which provides a concise way to handle multiple patterns with corresponding expressions.

For example:

 var description = size switch {
     < 0 => "negative",
     0 => "zero",
     > 0 => "positive"
 };

 var color = (r, g, b) switch {
     var (r, g, b) when r == g && g == b => "grayscale",
     ( > 128, _, _) => "bright red",
     _ => "other"
 };
 
  • Constructor Details

    • SwitchExpression

      public SwitchExpression()
  • Method Details

    • getExpression

      public org.openrewrite.java.tree.Expression getExpression()
    • withExpression

      public Cs.SwitchExpression withExpression(org.openrewrite.java.tree.Expression expression)
    • getArms

      public List<Cs.SwitchExpressionArm> getArms()
    • withArms

    • getType

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

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