Expression.New Method (Type)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Creates a NewExpression that represents calling the parameterless constructor of the specified type.
Assembly: System.Core (in System.Core.dll)
Parameters
- type
- Type: System.Type
A Type that has a constructor that takes no arguments.
Return Value
Type: System.Linq.Expressions.NewExpressionA NewExpression that has the NodeType property equal to New and the Constructor property set to the ConstructorInfo that represents the constructor without parameters for the specified type.
| Exception | Condition |
|---|---|
| ArgumentNullException | type is Nothing. |
| ArgumentException | The type that type represents does not have a constructor without parameters. |
The type parameter must represent a type that has a constructor without parameters.
The Arguments and Members properties of the resulting NewExpression are empty collections. The Type property is equal to type.
The following example demonstrates how to use the New(Type) method to create a NewExpression that represents constructing a new instance of a dictionary object by calling the constructor without parameters.
' Create a NewExpression that represents constructing ' a new instance of Dictionary(Of Integer, String). Dim newDictionaryExpression As System.Linq.Expressions.NewExpression = _ System.Linq.Expressions.Expression.[New]( _ Type.GetType("System.Collections.Generic.Dictionary`2[System.Int32, System.String]")) outputBlock.Text &= newDictionaryExpression.ToString() & vbCrLf ' This code produces the following output: ' ' new Dictionary`2()