语言

Expression.New 方法

定义

创建 NewExpression。

重载

名称 说明
New(ConstructorInfo)

创建一个 NewExpression 表示调用不带参数的指定构造函数。

New(Type)

创建一个 NewExpression 表示调用指定类型的无参数构造函数。

New(ConstructorInfo, IEnumerable<Expression>)

创建一个 NewExpression 表示使用指定参数调用指定构造函数的函数。

New(ConstructorInfo, Expression[])

创建一个 NewExpression 表示使用指定参数调用指定构造函数的函数。

New(ConstructorInfo, IEnumerable<Expression>, IEnumerable<MemberInfo>)

创建一个 NewExpression 表示使用指定参数调用指定构造函数的函数。 指定访问构造函数初始化字段的成员。

New(ConstructorInfo, IEnumerable<Expression>, MemberInfo[])

创建一个 NewExpression 表示使用指定参数调用指定构造函数的函数。 访问构造函数初始化字段的成员被指定为数组。

New(ConstructorInfo)

Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs

创建一个 NewExpression 表示调用不带参数的指定构造函数。

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor);
static member New : System.Reflection.ConstructorInfo -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo) As NewExpression

参数

constructor
ConstructorInfo

要 ConstructorInfo 设置的属性 Constructor 等于。

返回

一个 NewExpression 属性 NodeType 等于 New 和 Constructor 属性设置为指定值。

例外

constructor 是 null。

表示至少一个参数的构造函数 constructor 。

注解

Arguments生成的Members集合和NewExpression属性为空集合。 该 Type 属性表示由 constructor.

适用于

New(Type)

Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs

创建一个 NewExpression 表示调用指定类型的无参数构造函数。

public:
 static System::Linq::Expressions::NewExpression ^ New(Type ^ type);
public static System.Linq.Expressions.NewExpression New(Type type);
static member New : Type -> System.Linq.Expressions.NewExpression
Public Shared Function New (type As Type) As NewExpression

参数

type
Type

Type具有不带任何参数的构造函数的构造函数。

返回

一个NewExpression属性NodeType等于NewConstructor和属性设置为ConstructorInfo表示没有指定类型的参数的构造函数的属性。

例外

type 是 null。

表示的类型 type 没有没有参数的构造函数。

示例

下面的示例演示如何使用 New(Type) 该方法创建一个 NewExpression 表示通过调用不带参数的构造函数来构造字典对象的新实例。

// Create a NewExpression that represents constructing
// a new instance of Dictionary<int, string>.
System.Linq.Expressions.NewExpression newDictionaryExpression =
    System.Linq.Expressions.Expression.New(typeof(Dictionary<int, string>));

Console.WriteLine(newDictionaryExpression.ToString());

// This code produces the following output:
//
// new Dictionary`2()
' 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]"))

Console.WriteLine(newDictionaryExpression.ToString())

' This code produces the following output:
'
' new Dictionary`2()

注解

该 type 参数必须表示具有无参数的构造函数的类型。

Arguments生成的Members集合和NewExpression属性为空集合。 该 Type 属性等于 type.

适用于

New(ConstructorInfo, IEnumerable<Expression>)

Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs

创建一个 NewExpression 表示使用指定参数调用指定构造函数的函数。

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments);
static member New : System.Reflection.ConstructorInfo * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo, arguments As IEnumerable(Of Expression)) As NewExpression

参数

constructor
ConstructorInfo

要 ConstructorInfo 设置的属性 Constructor 等于。

arguments
IEnumerable<Expression>

IEnumerable<T>包含Expression用于填充Arguments集合的对象。

返回

一个NewExpression属性NodeType等于New和ConstructorArguments属性设置为指定值。

例外

constructor 是 null。

-或-

的元素为 argumentsnull.

该 arguments 参数不包含与表示的构造函数 constructor 的参数数相同的元素数。

-或-

Type元素的属性arguments不能分配给表示的构造函数constructor的相应参数的类型。

注解

该 arguments 参数必须包含与构造 constructor函数所表示的参数数相同的元素数。 arguments如果是null,则将其视为空,生成的ArgumentsNewExpression属性为空集合。

生成的TypeNewExpression属性表示由constructor该构造函数的声明类型。 该 Members 属性是一个空集合。

适用于

New(ConstructorInfo, Expression[])

Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs

创建一个 NewExpression 表示使用指定参数调用指定构造函数的函数。

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, params System.Linq.Expressions.Expression[] arguments);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, params System.Linq.Expressions.Expression[]? arguments);
static member New : System.Reflection.ConstructorInfo * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo, ParamArray arguments As Expression()) As NewExpression

参数

constructor
ConstructorInfo

要 ConstructorInfo 设置的属性 Constructor 等于。

arguments
Expression[]

用于填充Expression集合的对象数组Arguments。

返回

一个NewExpression属性NodeType等于New和ConstructorArguments属性设置为指定值。

例外

constructor 是 null。

-或-

的元素为 argumentsnull.

长度 arguments 与表示的构造函数 constructor 的参数数匹配。

-或-

Type元素的属性arguments不能分配给表示的构造函数constructor的相应参数的类型。

注解

该 arguments 参数必须包含与构造 constructor函数所表示的参数数相同的元素数。 arguments如果是null,则将其视为空,生成的ArgumentsNewExpression属性为空集合。

生成的TypeNewExpression属性表示由constructor该构造函数的声明类型。 该 Members 属性是一个空集合。

适用于

New(ConstructorInfo, IEnumerable<Expression>, IEnumerable<MemberInfo>)

Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs

创建一个 NewExpression 表示使用指定参数调用指定构造函数的函数。 指定访问构造函数初始化字段的成员。

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments, System::Collections::Generic::IEnumerable<System::Reflection::MemberInfo ^> ^ members);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments, System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo> members);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Property metadata or other accessor may be trimmed.")]
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments, System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>? members);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments, System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>? members);
static member New : System.Reflection.ConstructorInfo * seq<System.Linq.Expressions.Expression> * seq<System.Reflection.MemberInfo> -> System.Linq.Expressions.NewExpression
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Property metadata or other accessor may be trimmed.")>]
static member New : System.Reflection.ConstructorInfo * seq<System.Linq.Expressions.Expression> * seq<System.Reflection.MemberInfo> -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo, arguments As IEnumerable(Of Expression), members As IEnumerable(Of MemberInfo)) As NewExpression

参数

constructor
ConstructorInfo

要 ConstructorInfo 设置的属性 Constructor 等于。

arguments
IEnumerable<Expression>

IEnumerable<T>包含Expression用于填充Arguments集合的对象。

members
IEnumerable<MemberInfo>

IEnumerable<T>包含MemberInfo用于填充Members集合的对象。

返回

NewExpression一个属性NodeType等于New和ConstructorArgumentsMembers属性设置为指定值。

特性

例外

constructor 是 null。

-或-

的元素为 argumentsnull.

-或-

的元素为 membersnull.

该 arguments 参数不包含与表示的构造函数 constructor 的参数数相同的元素数。

-或-

Type元素的属性arguments不能分配给表示的构造函数constructor的相应参数的类型。

-或-

该 members 参数的元素 arguments数与 .

-或-

一 arguments 个元素具有一个属性,表示一个 Type 类型,该类型不可分配给由相应元素 members表示的成员的类型。

注解

该 arguments 参数必须包含与构造 constructor函数所表示的参数数相同的元素数。 arguments如果是null,则将其视为空,生成的ArgumentsNewExpression属性为空集合。

members如果是null,Members则生成的NewExpression属性为空集合。 否则members,它必须具有与每个元素相同的元素null数,并且每个元素不得相同arguments。null 每个元素 members 必须是一个 PropertyInfo或 FieldInfoMethodInfo 表示由其 constructor表示的构造函数的声明类型的实例成员。 如果它表示属性,则属性必须具有 get 访问器。 每个元素的argumentsmembers相应元素必须具有一个属性,该属性表示一个Type可分配给元素所表示的成员members类型的属性。

生成的TypeNewExpression属性表示表示表示的构造函数constructor的声明类型。

适用于

New(ConstructorInfo, IEnumerable<Expression>, MemberInfo[])

Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs
Source:
NewExpression.cs

创建一个 NewExpression 表示使用指定参数调用指定构造函数的函数。 访问构造函数初始化字段的成员被指定为数组。

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments, ... cli::array <System::Reflection::MemberInfo ^> ^ members);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments, params System.Reflection.MemberInfo[] members);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Property metadata or other accessor may be trimmed.")]
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments, params System.Reflection.MemberInfo[]? members);
public static System.Linq.Expressions.NewExpression New(System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments, params System.Reflection.MemberInfo[]? members);
static member New : System.Reflection.ConstructorInfo * seq<System.Linq.Expressions.Expression> * System.Reflection.MemberInfo[] -> System.Linq.Expressions.NewExpression
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The Property metadata or other accessor may be trimmed.")>]
static member New : System.Reflection.ConstructorInfo * seq<System.Linq.Expressions.Expression> * System.Reflection.MemberInfo[] -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo, arguments As IEnumerable(Of Expression), ParamArray members As MemberInfo()) As NewExpression

参数

constructor
ConstructorInfo

要 ConstructorInfo 设置的属性 Constructor 等于。

arguments
IEnumerable<Expression>

IEnumerable<T>包含Expression用于填充Arguments集合的对象。

members
MemberInfo[]

用于填充MemberInfo集合的对象数组Members。

返回

NewExpression一个属性NodeType等于New和ConstructorArgumentsMembers属性设置为指定值。

特性

例外

constructor 是 null。

-或-

的元素为 argumentsnull.

-或-

的元素为 membersnull.

该 arguments 参数不包含与表示的构造函数 constructor 的参数数相同的元素数。

-或-

Type元素的属性arguments不能分配给表示的构造函数constructor的相应参数的类型。

-或-

该 members 参数的元素 arguments数与 .

-或-

一 arguments 个元素具有一个属性,表示一个 Type 类型,该类型不可分配给由相应元素 members表示的成员的类型。

注解

该 arguments 参数必须包含与构造 constructor函数所表示的参数数相同的元素数。 arguments如果是null,则将其视为空,生成的ArgumentsNewExpression属性为空集合。

members如果是null,Members则生成的NewExpression属性为空集合。 否则members,它必须具有与每个元素相同的元素null数,并且每个元素不得相同arguments。null 每个元素 members 必须是一个 PropertyInfo或 FieldInfoMethodInfo 表示由其 constructor表示的构造函数的声明类型的实例成员。 如果它表示属性,该属性必须能够检索关联字段的值。 每个元素的argumentsmembers相应元素必须具有一个属性,该属性表示一个Type可分配给元素所表示的成员members类型的属性。

生成的TypeNewExpression属性表示表示表示的构造函数constructor的声明类型。

适用于