次の方法で共有


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

定義

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

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

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

type
Type

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

戻り値

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

例外

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)

注釈

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

適用対象