Partager via


Expression.NewArrayInit Méthode

Définition

Crée un NewArrayExpression tableau unidimensionnel qui représente la création d’un tableau unidimensionnel et l’initialise à partir d’une liste d’éléments.

Surcharges

Nom Description
NewArrayInit(Type, IEnumerable<Expression>)

Crée un NewArrayExpression tableau unidimensionnel qui représente la création d’un tableau unidimensionnel et l’initialise à partir d’une liste d’éléments.

NewArrayInit(Type, Expression[])

Crée un NewArrayExpression tableau unidimensionnel qui représente la création d’un tableau unidimensionnel et l’initialise à partir d’une liste d’éléments.

NewArrayInit(Type, IEnumerable<Expression>)

Source:
NewArrayExpression.cs
Source:
NewArrayExpression.cs
Source:
NewArrayExpression.cs
Source:
NewArrayExpression.cs
Source:
NewArrayExpression.cs

Crée un NewArrayExpression tableau unidimensionnel qui représente la création d’un tableau unidimensionnel et l’initialise à partir d’une liste d’éléments.

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

Paramètres

type
Type

Qui Type représente le type d’élément du tableau.

initializers
IEnumerable<Expression>

Qui IEnumerable<T> contient des Expression objets à utiliser pour remplir la Expressions collection.

Retours

Qui NewArrayExpression a la NodeType propriété égale à NewArrayInit et la Expressions propriété définie sur la valeur spécifiée.

Attributs

Exceptions

type ou initializers est null.

- ou -

Un élément de initializers .null

Propriété Type d’un élément de initializers représente un type qui n’est pas assignable au type qui type représente.

Exemples

L’exemple suivant montre comment utiliser la NewArrayInit méthode pour créer une arborescence d’expressions qui représente la création d’un tableau de chaînes unidimensionnel initialisé avec une liste d’expressions de chaîne.

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"}

Remarques

La Type propriété de chaque élément de initializers doit représenter un type qui est assignable au type représenté par type, éventuellement après son guillemet.

Note

Un élément ne sera cité que si type c’est Expressionle cas . Le guillemet signifie que l’élément est encapsulé dans un Quote nœud. Le nœud résultant est un UnaryExpression dont Operand la propriété est l’élément .initializers

La Type propriété du résultat NewArrayExpression représente un type de tableau dont le rang est 1 et dont le type d’élément est type.

S’applique à

NewArrayInit(Type, Expression[])

Source:
NewArrayExpression.cs
Source:
NewArrayExpression.cs
Source:
NewArrayExpression.cs
Source:
NewArrayExpression.cs
Source:
NewArrayExpression.cs

Crée un NewArrayExpression tableau unidimensionnel qui représente la création d’un tableau unidimensionnel et l’initialise à partir d’une liste d’éléments.

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

Paramètres

type
Type

Qui Type représente le type d’élément du tableau.

initializers
Expression[]

Tableau d’objets Expression à utiliser pour remplir la Expressions collection.

Retours

Qui NewArrayExpression a la NodeType propriété égale à NewArrayInit et la Expressions propriété définie sur la valeur spécifiée.

Attributs

Exceptions

type ou initializers est null.

- ou -

Un élément de initializers .null

Propriété Type d’un élément de initializers représente un type qui n’est pas assignable au type type.

Exemples

L’exemple suivant montre comment utiliser la NewArrayInit méthode pour créer une arborescence d’expressions qui représente la création d’un tableau de chaînes unidimensionnel initialisé avec une liste d’expressions de chaîne.

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"}

Remarques

La Type propriété de chaque élément de initializers doit représenter un type qui est assignable au type représenté par type, éventuellement après son guillemet.

Note

Un élément ne sera cité que si type c’est Expressionle cas . Le guillemet signifie que l’élément est encapsulé dans un Quote nœud. Le nœud résultant est un UnaryExpression dont Operand la propriété est l’élément .initializers

La Type propriété du résultat NewArrayExpression représente un type de tableau dont le rang est 1 et dont le type d’élément est type.

S’applique à