Expression.New 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立 NewExpression。
多載
| 名稱 | Description |
|---|---|
| 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一個屬性等NodeType於 ,New屬性Constructor設為指定值的 。
例外狀況
constructor 是 null。
constructor 表示的建構函式至少有一個參數。
備註
所產生 Arguments 的 Members 和 NewExpression 屬性是空的集合。
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
參數
傳回
NewExpression,其 NodeType 屬性等於 New,並將 Constructor 屬性設定為 ConstructorInfo,代表沒有指定型別參數的建構函式。
例外狀況
type 是 null。
type 所代表的類型沒有沒有參數的建構函式。
範例
下列範例示範如何使用 New(Type) 方法來建立 NewExpression,這個 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>)
建立 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且 Constructor 和 Arguments 屬性設定為指定值的 a。
例外狀況
arguments 參數不包含與 constructor 表示之建構函式的參數數目相同的項目數目。
-或-
Type 專案的 arguments 屬性無法指派給 constructor 所表示之建構函式之對應參數的類型。
備註
arguments 參數必須包含與 constructor所表示之建構函式的參數數目相同的項目數目。 如果 arguments 是 null,則會將其視為空白,而所產生 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一個屬性等NodeType於 ,New且 Constructor 和 Arguments 屬性設定為指定值的 a。
例外狀況
arguments 長度與 constructor 所代表建構函式的參數數目相符。
-或-
Type 專案的 arguments 屬性無法指派給 constructor 所表示之建構函式之對應參數的類型。
備註
arguments 參數必須包含與 constructor所表示之建構函式的參數數目相同的項目數目。 如果 arguments 是 null,則會將其視為空白,而所產生 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);
[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 A 的屬性等NodeType於 New 和 Constructor,Arguments屬性Members設定為指定值。
- 屬性
例外狀況
arguments 參數不包含與 constructor 表示之建構函式的參數數目相同的項目數目。
-或-
Type 專案的 arguments 屬性無法指派給 constructor 所表示之建構函式之對應參數的類型。
-或-
members 參數的元素數目與 arguments不同。
-或-
arguments 的專案具有 Type 屬性,表示無法指派給 members對應專案所表示之成員型別的型別。
備註
arguments 參數必須包含與 constructor所表示之建構函式的參數數目相同的項目數目。 如果 arguments 是 null,則會將其視為空白,而所產生 Arguments 的 NewExpression 屬性是空的集合。
如果 members 是 null,則產生的 MembersNewExpression 屬性是空的集合。 如果 members 不是 null,它必須具有與 arguments 相同的項目數目,而且每個元素不得 null。 每個 members 項目都必須是 PropertyInfo、FieldInfo 或 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);
[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 A 的屬性等NodeType於 New 和 Constructor,Arguments屬性Members設定為指定值。
- 屬性
例外狀況
arguments 參數不包含與 constructor 表示之建構函式的參數數目相同的項目數目。
-或-
Type 專案的 arguments 屬性無法指派給 constructor 所表示之建構函式之對應參數的類型。
-或-
members 參數的元素數目與 arguments不同。
-或-
arguments 的專案具有 Type 屬性,表示無法指派給 members對應專案所表示之成員型別的型別。
備註
arguments 參數必須包含與 constructor所表示之建構函式的參數數目相同的項目數目。 如果 arguments 是 null,則會將其視為空白,而所產生 Arguments 的 NewExpression 屬性是空的集合。
如果 members 是 null,則產生的 MembersNewExpression 屬性是空的集合。 如果 members 不是 null,它必須具有與 arguments 相同的項目數目,而且每個元素不得 null。 每個 members 項目都必須是 PropertyInfo、FieldInfo 或 MethodInfo,代表由 constructor所表示之建構函式之宣告型別上的實例成員。 如果屬性代表屬性,屬性必須能夠擷取相關聯欄位的值。
arguments 每個項目的對應專案 members 必須具有 Type 屬性,代表可指派給 members 專案所代表之成員類型的類型。
所產生 Type 的 NewExpression 屬性代表 constructor 所表示之建構函式的宣告型別。