Expression.NewArrayInit Metoda

Definicja

Tworzy obiekt NewArrayExpression reprezentujący tworzenie tablicy jednowymiarowej i inicjowanie jej na podstawie listy elementów.

Przeciążenia

NewArrayInit(Type, IEnumerable<Expression>)

Tworzy obiekt NewArrayExpression reprezentujący tworzenie tablicy jednowymiarowej i inicjowanie jej na podstawie listy elementów.

NewArrayInit(Type, Expression[])

Tworzy obiekt NewArrayExpression reprezentujący tworzenie tablicy jednowymiarowej i inicjowanie jej na podstawie listy elementów.

NewArrayInit(Type, IEnumerable<Expression>)

Źródło:
NewArrayExpression.cs
Źródło:
NewArrayExpression.cs
Źródło:
NewArrayExpression.cs

Tworzy obiekt NewArrayExpression reprezentujący tworzenie tablicy jednowymiarowej i inicjowanie jej na podstawie listy elementów.

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);
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

Obiekt Type reprezentujący typ elementu tablicy.

initializers
IEnumerable<Expression>

Obiekt IEnumerable<T> zawierający Expression obiekty używane do wypełniania kolekcji Expressions .

Zwraca

WłaściwośćNewArrayExpression, która ma właściwość równą NewArrayInitNodeType i Expressions właściwość ustawioną na określoną wartość.

Wyjątki

type lub initializers ma wartość null.

-lub-

Element elementu initializers to null.

Właściwość Type elementu initializers reprezentuje typ, który nie można przypisać do typu, który type reprezentuje.

Przykłady

W poniższym przykładzie pokazano, jak za pomocą NewArrayInit metody utworzyć drzewo wyrażeń reprezentujące utworzenie jednowymiarowej tablicy ciągów zainicjowanej przy użyciu listy wyrażeń ciągu.

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

Uwagi

Właściwość Type każdego elementu initializers musi reprezentować typ, który można przypisać do typu reprezentowanego przez type, prawdopodobnie po cytowaniu.

Uwaga

Element będzie cytowany tylko wtedy, gdy type ma wartość Expression. Cudzysłów oznacza, że element jest owinięty w węźle Quote . Wynikowy UnaryExpression węzeł jest, którego Operand właściwość jest elementem initializers.

Właściwość Type wynikowego NewArrayExpression reprezentuje typ tablicy, którego ranga to 1 i którego typ elementu to type.

Dotyczy

NewArrayInit(Type, Expression[])

Źródło:
NewArrayExpression.cs
Źródło:
NewArrayExpression.cs
Źródło:
NewArrayExpression.cs

Tworzy obiekt NewArrayExpression reprezentujący tworzenie tablicy jednowymiarowej i inicjowanie jej na podstawie listy elementów.

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);
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

Obiekt Type reprezentujący typ elementu tablicy.

initializers
Expression[]

Tablica Expression obiektów do użycia w celu wypełnienia kolekcji Expressions .

Zwraca

WłaściwośćNewArrayExpression, która ma właściwość równą NewArrayInitNodeType i Expressions właściwość ustawioną na określoną wartość.

Wyjątki

type lub initializers ma wartość null.

-lub-

Element elementu initializers to null.

Właściwość Type elementu initializers reprezentuje typ, który nie można przypisać do typu type.

Przykłady

W poniższym przykładzie pokazano, jak za pomocą NewArrayInit metody utworzyć drzewo wyrażeń reprezentujące utworzenie jednowymiarowej tablicy ciągów zainicjowanej przy użyciu listy wyrażeń ciągu.

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

Uwagi

Właściwość Type każdego elementu initializers musi reprezentować typ, który można przypisać do typu reprezentowanego przez type, prawdopodobnie po cytowaniu.

Uwaga

Element będzie cytowany tylko wtedy, gdy type ma wartość Expression. Cudzysłów oznacza, że element jest owinięty w węźle Quote . Wynikowy UnaryExpression węzeł jest, którego Operand właściwość jest elementem initializers.

Właściwość Type wynikowego NewArrayExpression reprezentuje typ tablicy, którego ranga to 1 i którego typ elementu to type.

Dotyczy