Expression.TypeAs(Expression, Type) メソッド
定義
変換が失敗した場合に UnaryExpression が提供される明示的な参照変換またはボックス化変換を表す null
を作成します。Creates a UnaryExpression that represents an explicit reference or boxing conversion where null
is supplied if the conversion fails.
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
パラメーター
- expression
- Expression
Expression プロパティを等しく設定する Operand。An Expression to set the Operand property equal to.
戻り値
UnaryExpression と等しい NodeType プロパティと、指定した値に設定された TypeAs プロパティおよび Operand プロパティを含む Type。A UnaryExpression that has the NodeType property equal to TypeAs and the Operand and Type properties set to the specified values.
例外
expression
または type
が null
です。expression
or type
is null
.
例
次の例は、 TypeAs(Expression, Type)メソッドを使用して、null 非許容の整数式から null 許容の整数型への参照変換を表すをUnaryExpression作成する方法を示しています。The following example demonstrates how to use the TypeAs(Expression, Type) method to create a UnaryExpression that represents the reference conversion of a non-nullable integer expression to the nullable integer type.
// 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)
注釈
結果として得UnaryExpressionらnull
れるのプロパティはです。MethodThe Method property of the resulting UnaryExpression is null
. プロパティとプロパティは両方false
とIsLiftedToNullもです。 IsLiftedThe IsLifted and IsLiftedToNull properties are both false
.