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)

创建一个表示调用不带自变量的指定构造函数的 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

一个 NewExpression,其 NodeType 属性等于 New,并且其 Constructor 属性设置为指定值。

例外

constructornull

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

注解

Arguments生成的NewExpression集合和Members属性为空集合。 该 Type 属性表示由 constructor. 表示的构造函数的声明类型。

适用于

New(Type)

创建一个表示调用指定类型的无参数构造函数的 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

一个 NewExpression,其 NodeType 属性等于 New,并且其 Constructor 属性设置为 ConstructorInfo,这表示不带指定类型的参数的构造函数。

例外

typenull

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生成的NewExpression集合和Members属性为空集合。 该 Type 属性等于 type.

适用于

New(ConstructorInfo, IEnumerable<Expression>)

创建一个表示调用带指定参数的指定构造函数的 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

一个 NewExpression,其 NodeType 属性等于 New,并且其 ConstructorArguments 属性设置为指定值。

例外

constructornull

  • 或 - arguments 的元素为 null

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

  • 或 - arguments 的元素的 Type 属性不能赋给 constructor 表示的构造函数的相应参数类型。

注解

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

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

适用于

New(ConstructorInfo, Expression[])

创建一个表示调用带指定参数的指定构造函数的 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

一个 NewExpression,其 NodeType 属性等于 New,并且其 ConstructorArguments 属性设置为指定值。

例外

constructornull

  • 或 - arguments 的元素为 null

arguments 的长度与 constructor 表示的构造函数的参数数目不符。

  • 或 - arguments 的元素的 Type 属性不能赋给 constructor 表示的构造函数的相应参数类型。

注解

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

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

适用于

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

创建一个表示调用带指定参数的指定构造函数的 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);
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
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

一个 NewExpression,其 NodeType 属性等于 New,并且其 ConstructorArgumentsMembers 属性设置为指定值。

例外

constructornull

  • 或 - arguments 的元素为 null

  • 或 - members 的元素为 null

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

  • 或 - arguments 的元素的 Type 属性不能赋给 constructor 表示的构造函数的相应参数类型。

  • 或 - members 参数没有包含与 arguments 相同数量的元素。

  • 或 - arguments 的元素具有 Type 属性,该属性表示不能赋给 members 的相应元素所表示的成员类型的类型。

注解

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

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

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

适用于

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

创建一个表示调用带指定参数的指定构造函数的 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);
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
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

一个 NewExpression,其 NodeType 属性等于 New,并且其 ConstructorArgumentsMembers 属性设置为指定值。

例外

constructornull

  • 或 - arguments 的元素为 null

  • 或 - members 的元素为 null

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

  • 或 - arguments 的元素的 Type 属性不能赋给 constructor 表示的构造函数的相应参数类型。

  • 或 - members 参数没有包含与 arguments 相同数量的元素。

  • 或 - arguments 的元素具有 Type 属性,该属性表示不能赋给 members 的相应元素所表示的成员类型的类型。

注解

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

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

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

适用于