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產生的 NewExpressionMembers 屬性是空的集合。 屬性 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產生的 NewExpressionMembers 屬性是空的集合。 屬性 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 表示之建構函式的參數數目相同的專案數目。 如果 argumentsnull ,則視為空白,而 Arguments 產生的 NewExpression 屬性為空集合。

產生的 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 表示之建構函式的參數數目相同的專案數目。 如果 argumentsnull ,則視為空白,而 Arguments 產生的 NewExpression 屬性為空集合。

產生的 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 表示之建構函式的參數數目相同的專案數目。 如果 argumentsnull ,則視為空白,而 Arguments 產生的 NewExpression 屬性為空集合。

如果 membersnullMembers 則產生的 NewExpression 屬性是空集合。 如果 members 不是 null ,則它必須具有相同的元素 arguments 數目,而且每個元素不得為 null 。 的每個專案 members 都必須是 PropertyInfoFieldInfoMethodInfo 代表 所 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 表示之建構函式的參數數目相同的專案數目。 如果 argumentsnull ,則視為空白,而 Arguments 產生的 NewExpression 屬性為空集合。

如果 membersnullMembers 則產生的 NewExpression 屬性是空集合。 如果 members 不是 null ,則它必須具有相同的元素 arguments 數目,而且每個元素不得為 null 。 的每個專案 members 都必須是 PropertyInfoFieldInfoMethodInfo 代表 所 constructor 表示之建構函式宣告類型的實例成員。 如果它代表屬性,屬性必須能夠擷取相關聯欄位的值。 之每個專案的對應專案 arguments members 必須具有 Type 屬性,表示可指派給專案所代表成員 members 型別的型別。

Type產生的 NewExpression 屬性代表所代表之建構函 constructor 式的宣告型別。

適用於