New Method (Type)

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.

Namespace:  System.Linq.Expressions
Assembly:  System.Core (in System.Core.dll)

'Declaration
Public Shared Function New ( _
	type As Type _
) As NewExpression

Parameters

type
Type: System.Type
A Type that has a constructor that takes no arguments.

Return Value

Type: System.Linq.Expressions.NewExpression
A 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.

ExceptionCondition
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()


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft