NewObjectExpression Class

Represents an object instantiation expression using the new keyword.

public class NewObjectExpression : Expression

Example

var newObj = new NewObjectExpression(typeof(StringBuilder));
var newObjWithArgs = new NewObjectExpression(typeof(StringBuilder), new LiteralExpression("initial value"));

Assert.Equal("new global::System.Text.StringBuilder()", newObj.ToCsharpString());
Assert.Equal("new global::System.Text.StringBuilder(\"initial value\")", newObjWithArgs.ToCsharpString());
Inheritance
Expression NewObjectExpression

Constructors

NameDescription
NewObjectExpression()
NewObjectExpression(TypeReference?, Expression[])Initializes a new instance of the NewObjectExpression class with the specified type and constructor arguments.

NewObjectExpression overloads

NewObjectExpression()

NewObjectExpression.cs
public NewObjectExpression()

No documentation is available.

NewObjectExpression(TypeReference?, Expression[])

NewObjectExpression.cs

Initializes a new instance of the NewObjectExpression class with the specified type and constructor arguments.

public NewObjectExpression(TypeReference? type, params Expression[] arguments)
Parameters
type TypeReference?
The type to instantiate.
arguments Expression[]
The constructor arguments.

Properties

NameDescription
Arguments
Type
public CodeObjectCollection<Expression> Arguments { get; }

No documentation is available.

public TypeReference? Type { get; set; }

Property value

TypeReference?

No documentation is available.