Sdílet prostřednictvím


Expression.NewArrayInit Metoda

Definice

Vytvoří objekt NewArrayExpression , který představuje vytvoření jednorozměrného pole a inicializaci ze seznamu prvků.

Přetížení

Name Description
NewArrayInit(Type, IEnumerable<Expression>)

Vytvoří objekt NewArrayExpression , který představuje vytvoření jednorozměrného pole a inicializaci ze seznamu prvků.

NewArrayInit(Type, Expression[])

Vytvoří objekt NewArrayExpression , který představuje vytvoření jednorozměrného pole a inicializaci ze seznamu prvků.

NewArrayInit(Type, IEnumerable<Expression>)

Zdroj:
NewArrayExpression.cs
Zdroj:
NewArrayExpression.cs
Zdroj:
NewArrayExpression.cs
Zdroj:
NewArrayExpression.cs
Zdroj:
NewArrayExpression.cs

Vytvoří objekt NewArrayExpression , který představuje vytvoření jednorozměrného pole a inicializaci ze seznamu prvků.

public:
 static System::Linq::Expressions::NewArrayExpression ^ NewArrayInit(Type ^ type, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ initializers);
public static System.Linq.Expressions.NewArrayExpression NewArrayInit(Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> initializers);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating arrays at runtime requires dynamic code generation.")]
public static System.Linq.Expressions.NewArrayExpression NewArrayInit(Type type, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> initializers);
static member NewArrayInit : Type * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.NewArrayExpression
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating arrays at runtime requires dynamic code generation.")>]
static member NewArrayInit : Type * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.NewArrayExpression
Public Shared Function NewArrayInit (type As Type, initializers As IEnumerable(Of Expression)) As NewArrayExpression

Parametry

type
Type

A Type , který představuje typ prvku pole.

initializers
IEnumerable<Expression>

Objekt IEnumerable<T> obsahující Expression objekty, které se mají použít k naplnění Expressions kolekce.

Návraty

ANewArrayExpression, který má vlastnost rovna NewArrayInitNodeType a Expressions vlastnost nastavena na zadanou hodnotu.

Atributy

Výjimky

type nebo initializers je null.

nebo

initializers Prvek je null.

Type Vlastnost elementu initializers představuje typ, který nelze přiřadit k typu, který type představuje.

Příklady

Následující příklad ukazuje, jak použít metodu NewArrayInit k vytvoření stromu výrazu, který představuje vytvoření jednorozměrného řetězcového pole, které je inicializováno se seznamem řetězcových výrazů.

List<System.Linq.Expressions.Expression> trees =
    new List<System.Linq.Expressions.Expression>()
        { System.Linq.Expressions.Expression.Constant("oak"),
          System.Linq.Expressions.Expression.Constant("fir"),
          System.Linq.Expressions.Expression.Constant("spruce"),
          System.Linq.Expressions.Expression.Constant("alder") };

// Create an expression tree that represents creating and
// initializing a one-dimensional array of type string.
System.Linq.Expressions.NewArrayExpression newArrayExpression =
    System.Linq.Expressions.Expression.NewArrayInit(typeof(string), trees);

// Output the string representation of the Expression.
Console.WriteLine(newArrayExpression.ToString());

// This code produces the following output:
//
// new [] {"oak", "fir", "spruce", "alder"}
Dim trees As New System.Collections.Generic.List(Of System.Linq.Expressions.Expression) _
        (New System.Linq.Expressions.Expression() _
         {System.Linq.Expressions.Expression.Constant("oak"), _
          System.Linq.Expressions.Expression.Constant("fir"), _
          System.Linq.Expressions.Expression.Constant("spruce"), _
          System.Linq.Expressions.Expression.Constant("alder")})

' Create an expression tree that represents creating and  
' initializing a one-dimensional array of type string.
Dim newArrayExpression As System.Linq.Expressions.NewArrayExpression = _
    System.Linq.Expressions.Expression.NewArrayInit(Type.GetType("System.String"), trees)

' Output the string representation of the Expression.
Console.WriteLine(newArrayExpression.ToString())

' This code produces the following output:
'
' new [] {"oak", "fir", "spruce", "alder"}

Poznámky

Vlastnost Type každého prvku initializers musí představovat typ, který je přiřazen k typu reprezentovaný type, pravděpodobně po uvozování.

Poznámka:

Prvek bude citován pouze v případě, že type je Expression. Uvozování znamená, že prvek je zabalený do Quote uzlu. Výsledný uzel je jehož UnaryExpressionOperand vlastnost je prvek initializers.

Vlastnost Type výsledného NewArrayExpression představuje typ pole, jehož pořadí je 1 a jehož typ prvku je type.

Platí pro

NewArrayInit(Type, Expression[])

Zdroj:
NewArrayExpression.cs
Zdroj:
NewArrayExpression.cs
Zdroj:
NewArrayExpression.cs
Zdroj:
NewArrayExpression.cs
Zdroj:
NewArrayExpression.cs

Vytvoří objekt NewArrayExpression , který představuje vytvoření jednorozměrného pole a inicializaci ze seznamu prvků.

public:
 static System::Linq::Expressions::NewArrayExpression ^ NewArrayInit(Type ^ type, ... cli::array <System::Linq::Expressions::Expression ^> ^ initializers);
public static System.Linq.Expressions.NewArrayExpression NewArrayInit(Type type, params System.Linq.Expressions.Expression[] initializers);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating arrays at runtime requires dynamic code generation.")]
public static System.Linq.Expressions.NewArrayExpression NewArrayInit(Type type, params System.Linq.Expressions.Expression[] initializers);
static member NewArrayInit : Type * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.NewArrayExpression
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating arrays at runtime requires dynamic code generation.")>]
static member NewArrayInit : Type * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.NewArrayExpression
Public Shared Function NewArrayInit (type As Type, ParamArray initializers As Expression()) As NewArrayExpression

Parametry

type
Type

A Type , který představuje typ prvku pole.

initializers
Expression[]

Pole Expression objektů, které se mají použít k naplnění Expressions kolekce.

Návraty

ANewArrayExpression, který má vlastnost rovna NewArrayInitNodeType a Expressions vlastnost nastavena na zadanou hodnotu.

Atributy

Výjimky

type nebo initializers je null.

nebo

initializers Prvek je null.

Vlastnost Type prvku initializers představuje typ, který nelze přiřadit k typu type.

Příklady

Následující příklad ukazuje, jak použít metodu NewArrayInit k vytvoření stromu výrazu, který představuje vytvoření jednorozměrného řetězcového pole, které je inicializováno se seznamem řetězcových výrazů.

List<System.Linq.Expressions.Expression> trees =
    new List<System.Linq.Expressions.Expression>()
        { System.Linq.Expressions.Expression.Constant("oak"),
          System.Linq.Expressions.Expression.Constant("fir"),
          System.Linq.Expressions.Expression.Constant("spruce"),
          System.Linq.Expressions.Expression.Constant("alder") };

// Create an expression tree that represents creating and
// initializing a one-dimensional array of type string.
System.Linq.Expressions.NewArrayExpression newArrayExpression =
    System.Linq.Expressions.Expression.NewArrayInit(typeof(string), trees);

// Output the string representation of the Expression.
Console.WriteLine(newArrayExpression.ToString());

// This code produces the following output:
//
// new [] {"oak", "fir", "spruce", "alder"}
Dim trees As New System.Collections.Generic.List(Of System.Linq.Expressions.Expression) _
        (New System.Linq.Expressions.Expression() _
         {System.Linq.Expressions.Expression.Constant("oak"), _
          System.Linq.Expressions.Expression.Constant("fir"), _
          System.Linq.Expressions.Expression.Constant("spruce"), _
          System.Linq.Expressions.Expression.Constant("alder")})

' Create an expression tree that represents creating and  
' initializing a one-dimensional array of type string.
Dim newArrayExpression As System.Linq.Expressions.NewArrayExpression = _
    System.Linq.Expressions.Expression.NewArrayInit(Type.GetType("System.String"), trees)

' Output the string representation of the Expression.
Console.WriteLine(newArrayExpression.ToString())

' This code produces the following output:
'
' new [] {"oak", "fir", "spruce", "alder"}

Poznámky

Vlastnost Type každého prvku initializers musí představovat typ, který je přiřazen k typu reprezentovaný type, pravděpodobně po uvozování.

Poznámka:

Prvek bude citován pouze v případě, že type je Expression. Uvozování znamená, že prvek je zabalený do Quote uzlu. Výsledný uzel je jehož UnaryExpressionOperand vlastnost je prvek initializers.

Vlastnost Type výsledného NewArrayExpression představuje typ pole, jehož pořadí je 1 a jehož typ prvku je type.

Platí pro