Sdílet prostřednictvím


Expression.TypeAs(Expression, Type) Metoda

Definice

UnaryExpression Vytvoří, který představuje explicitní odkaz nebo boxing převod, kde null je zadán, pokud převod selže.

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

Parametry

expression
Expression

Operand Nastavení Expression vlastnosti rovno.

type
Type

A Type nastavit Type vlastnost rovná se.

Návraty

AUnaryExpression, který má vlastnost rovna TypeAsNodeType a Operand a Type vlastnosti nastaveny na zadané hodnoty.

Výjimky

expression nebo type je null.

Příklady

Následující příklad ukazuje, jak použít metodu TypeAs(Expression, Type) k vytvoření UnaryExpression , který představuje odkaz převod nenulovatelné celočíselného výrazu na typ integer s možnou hodnotou null.

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

Poznámky

Vlastnost Method výsledného UnaryExpression je null. IsLiftedToNull Obě vlastnosti IsLifted jsou falseoba .

Platí pro