Expression.TypeAs(Expression, Type) Methode

Definition

Erstellt eine UnaryExpression, die eine explizite Verweis- oder Boxingkonvertierung darstellt, bei der null zurückgegeben wird, wenn bei der Konvertierung ein Fehler auftritt.

public:
 static System::Linq::Expressions::UnaryExpression ^ TypeAs(System::Linq::Expressions::Expression ^ expression, Type ^ type);
public static System.Linq.Expressions.UnaryExpression TypeAs (System.Linq.Expressions.Expression expression, Type type);
static member TypeAs : System.Linq.Expressions.Expression * Type -> System.Linq.Expressions.UnaryExpression
Public Shared Function TypeAs (expression As Expression, type As Type) As UnaryExpression

Parameter

expression
Expression

Ein Expression, auf den die Operand-Eigenschaft festgelegt werden soll.

type
Type

Ein Type, auf das die Type-Eigenschaft festgelegt werden soll.

Gibt zurück

Ein UnaryExpression, bei dem die NodeType-Eigenschaft gleich TypeAs ist und die Operand-Eigenschaft sowie die Type-Eigenschaft auf die angegebenen Werte festgelegt sind.

Ausnahmen

expression oder type ist null.

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie die TypeAs(Expression, Type) -Methode verwendet wird, um eine UnaryExpression zu erstellen, die die Verweiskonvertierung eines ganzzahligen Ausdrucks ohne Nullable in den Nullable-Ganzzahltyp darstellt.

// Create a UnaryExpression that represents a
// conversion of an int to an int?.
System.Linq.Expressions.UnaryExpression typeAsExpression =
    System.Linq.Expressions.Expression.TypeAs(
        System.Linq.Expressions.Expression.Constant(34, typeof(int)),
        typeof(int?));

Console.WriteLine(typeAsExpression.ToString());

// This code produces the following output:
//
// (34 As Nullable`1)
' Create a UnaryExpression that represents a reference
' conversion of an Integer to an Integer? (a nullable Integer).
Dim typeAsExpression As System.Linq.Expressions.UnaryExpression = _
    System.Linq.Expressions.Expression.TypeAs( _
        System.Linq.Expressions.Expression.Constant(34, Type.GetType("System.Int32")), _
        Type.GetType("System.Nullable`1[System.Int32]"))

Console.WriteLine(typeAsExpression.ToString())

' This code produces the following output:
'
' (34 As Nullable`1)

Hinweise

Die Method -Eigenschaft des resultierenden UnaryExpression ist null. Die IsLifted Eigenschaften und IsLiftedToNull sind beide false.

Gilt für: