Class Cs.NewClass

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

public static final class Cs.NewClass extends Object implements Cs, org.openrewrite.java.tree.Statement, org.openrewrite.java.tree.Expression
Represents a C# new class instantiation expression, which can optionally include an object/collection initializer.

For example:

 // Simple new class without initializer
 new Person("John", 25)

 // New class with object initializer
 new Person { Name = "John", Age = 25 }

 // New class with collection initializer
 new List { 1, 2, 3 }

 // New class with constructor and initializer
 new Person("John") { Age = 25 }
 
The newClassCore field contains the basic class instantiation including constructor call, while the initializer field contains the optional object/collection initializer expressions wrapped in a JContainer to preserve whitespace around curly braces and between initializer expressions.
  • Constructor Details

    • NewClass

      public NewClass()
  • Method Details

    • acceptCSharp

      public <P> org.openrewrite.java.tree.J acceptCSharp(CSharpVisitor<P> v, P p)
      Specified by:
      acceptCSharp in interface Cs
    • getType

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

      public Cs.NewClass withType(@Nullable org.openrewrite.java.tree.JavaType type)
      Specified by:
      withType in interface org.openrewrite.java.tree.Expression
    • getCoordinates

      public org.openrewrite.java.tree.CoordinateBuilder.Statement getCoordinates()
      Specified by:
      getCoordinates in interface org.openrewrite.java.tree.Expression
      Specified by:
      getCoordinates in interface org.openrewrite.java.tree.Statement