Class Cs.SwitchStatement

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

public static final class Cs.SwitchStatement extends Object implements Cs, org.openrewrite.java.tree.Statement
Represents a C# switch statement for control flow based on pattern matching and case labels.

For example:

 switch(value) {
     case 1:
         Console.WriteLine("one");
         break;

     case int n when n > 0:
         Console.WriteLine("positive");
         break;

     case Person { Age: > 18 }:
         Console.WriteLine("adult");
         break;

     case string s:
         Console.WriteLine($"string: {s}");
         break;

     default:
         Console.WriteLine("default");
         break;
 }
 
  • Constructor Details

    • SwitchStatement

      public SwitchStatement()
  • Method Details

    • getExpression

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

      public Cs.SwitchStatement withExpression(List<org.openrewrite.java.tree.Expression> expression)
    • getSections

      public List<Cs.SwitchSection> getSections()
    • withSections

      public Cs.SwitchStatement withSections(List<Cs.SwitchSection> sections)
    • 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.Statement getCoordinates()
      Specified by:
      getCoordinates in interface org.openrewrite.java.tree.Statement
    • getPadding

      public Cs.SwitchStatement.Padding getPadding()