Expression.TypeAs(Expression, Type) メソッド

定義

変換が失敗した場合にUnaryExpressionが指定される明示的な参照またはボックス化変換を表すnullを作成します。

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

パラメーター

expression
Expression

Expression プロパティを等しい値に設定するOperand

type
Type

Type プロパティを等しく設定するType

返品

UnaryExpression プロパティが NodeType と等しく、TypeAsプロパティとOperandプロパティが指定した値に設定されているType

例外

expression または typenull

次の例では、 TypeAs(Expression, Type) メソッドを使用して、null 非許容整数式から null 許容整数型への参照変換を表す UnaryExpression を作成する方法を示します。

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

注釈

結果のMethodUnaryExpressionプロパティがnullIsLiftedプロパティとIsLiftedToNull プロパティの両方がfalse

適用対象