NewArrayExpression Třída

Definice

Představuje vytvoření nového pole a pravděpodobně inicializaci prvků nového pole.

public ref class NewArrayExpression : System::Linq::Expressions::Expression
public ref class NewArrayExpression sealed : System::Linq::Expressions::Expression
public class NewArrayExpression : System.Linq.Expressions.Expression
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating arrays at runtime requires dynamic code generation.")]
public class NewArrayExpression : System.Linq.Expressions.Expression
public sealed class NewArrayExpression : System.Linq.Expressions.Expression
type NewArrayExpression = class
    inherit Expression
[<System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Creating arrays at runtime requires dynamic code generation.")>]
type NewArrayExpression = class
    inherit Expression
Public Class NewArrayExpression
Inherits Expression
Public NotInheritable Class NewArrayExpression
Inherits Expression
Dědičnost
NewArrayExpression
Atributy

Příklady

Následující příklad vytvoří NewArrayExpression objekt, který představuje vytvoření a inicializaci jednorozměrného pole řetězců.

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

Další příklad vytvoří NewArrayExpression objekt, který představuje vytvoření dvojrozměrného pole řetězců.

// Create an expression tree that represents creating a
// two-dimensional array of type string with bounds [3,2].
System.Linq.Expressions.NewArrayExpression newArrayExpression =
    System.Linq.Expressions.Expression.NewArrayBounds(
            typeof(string),
            System.Linq.Expressions.Expression.Constant(3),
            System.Linq.Expressions.Expression.Constant(2));

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

// This code produces the following output:
//
// new System.String[,](3, 2)
' Create an expression tree that represents creating a string
' array with rank 2 and bounds (3,2).
Dim newArrayExpression As System.Linq.Expressions.NewArrayExpression = _
    System.Linq.Expressions.Expression.NewArrayBounds( _
            Type.GetType("System.String"), _
            System.Linq.Expressions.Expression.Constant(3), _
            System.Linq.Expressions.Expression.Constant(2))

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

' This code produces the following output:
'
' new System.String[,](3, 2)

Poznámky

Následující tabulka uvádí různé metody výroby, které můžete použít k vytvoření NewArrayExpression v závislosti na tom, co NodeType potřebujete.

NodeType Metody továrny
NewArrayBounds NewArrayBounds
NewArrayInit NewArrayInit

Vlastnosti

Name Description
CanReduce

Označuje, že uzel lze snížit na jednodušší uzel. Pokud se vrátí hodnota true, lze volat Reduce() k vytvoření snížené formy.

(Zděděno od Expression)
Expressions

Získá hranice pole, pokud hodnota NodeType vlastnosti je NewArrayBounds, nebo hodnoty inicializovat prvky nového pole, pokud je NodeTypehodnota NewArrayInit vlastnosti .

NodeType

Získá typ uzlu tohoto Expression.

(Zděděno od Expression)
Type

Získá statický typ výrazu, který představuje Expression .

Type

Získá statický typ výrazu, který představuje Expression .

(Zděděno od Expression)

Metody

Name Description
Accept(ExpressionVisitor)

Odešle konkrétní metodu návštěvy pro tento typ uzlu. MethodCallExpression Například volá .VisitMethodCall(MethodCallExpression)

Equals(Object)

Určuje, zda je zadaný objekt roven aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Získá Type aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Object.

(Zděděno od Object)
Reduce()

Zmenší tento uzel na jednodušší výraz. Pokud CanReduce vrátí hodnotu true, měl by vrátit platný výraz. Tato metoda může vrátit jiný uzel, který se musí snížit.

(Zděděno od Expression)
ReduceAndCheck()

Zmenší tento uzel na jednodušší výraz. Pokud CanReduce vrátí hodnotu true, měl by vrátit platný výraz. Tato metoda může vrátit jiný uzel, který se musí snížit.

(Zděděno od Expression)
ReduceExtensions()

Zmenšuje výraz na známý typ uzlu (který není uzel rozšíření), nebo pouze vrátí výraz, pokud je již známým typem.

(Zděděno od Expression)
ToString()

Vrátí textovou reprezentaci Expression.

(Zděděno od Expression)
Update(IEnumerable<Expression>)

Vytvoří nový výraz, který je podobný tomuto, ale použije zadané podřízené položky. Pokud jsou všechny podřízené položky stejné, vrátí tento výraz.

VisitChildren(ExpressionVisitor)

Zmenší uzel a potom zavolá delegáta návštěvníka na zkrácený výraz. Metoda vyvolá výjimku, pokud uzel není reducible.

(Zděděno od Expression)

Platí pro