Class Cs.DeclarationExpression

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

public static final class Cs.DeclarationExpression extends Object implements Cs, org.openrewrite.java.tree.Expression, org.openrewrite.java.tree.TypedTree
A declaration expression node represents a local variable declaration in an expression context. This is used in two primary scenarios in C#:
  • Out variable declarations: Method(out int x)
  • Deconstruction declarations: int (x, y) = GetPoint()
Example 1: Out variable declaration:
 if(int.TryParse(s, out int result)) {
     // use result
 }
 
Example 2: Deconstruction declaration:
 int (x, y) = point;
 ^^^^^^^^^^
 (int count, var (name, age)) = GetPersonDetails();
             ^^^^^^^^^^^^^^^ DeclarationExpression
                 ^^^^^^^^^^^ ParenthesizedVariableDesignation
  ^^^^^^^^^ DeclarationExpression
      ^^^^^ SingleVariableDesignation
 
  • Constructor Details

    • DeclarationExpression

      public DeclarationExpression()
  • Method Details

    • getType

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

      public Cs.DeclarationExpression withType(@Nullable org.openrewrite.java.tree.JavaType type)
      Specified by:
      withType in interface org.openrewrite.java.tree.Expression
      Specified by:
      withType in interface org.openrewrite.java.tree.TypedTree
    • 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