Expression.TypeAs(Expression, Type) Metodo

Definizione

Crea un oggetto UnaryExpression che rappresenta un riferimento esplicito o una conversione boxing in cui viene fornito null se la conversione non riesce.

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

Parametri

expression
Expression

Oggetto Expression su cui impostare la proprietà Operand.

type
Type

Oggetto Type su cui impostare la proprietà Type.

Restituisce

Oggetto UnaryExpression la cui proprietà NodeType è uguale a TypeAs e le cui proprietà Operand e Type sono impostate sui valori specificati.

Eccezioni

expression o type è null.

Esempio

Nell'esempio seguente viene illustrato come usare il TypeAs(Expression, Type) metodo per creare un UnaryExpression oggetto che rappresenta la conversione di riferimento di un'espressione integer non nullable al tipo integer nullable.

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

Commenti

La Method proprietà del risultato UnaryExpression è null. Le IsLifted proprietà e IsLiftedToNull sono entrambe false.

Si applica a