Expression.TypeIs(Expression, Type) 方法

定义

创建一个 TypeBinaryExpression

public:
 static System::Linq::Expressions::TypeBinaryExpression ^ TypeIs(System::Linq::Expressions::Expression ^ expression, Type ^ type);
public static System.Linq.Expressions.TypeBinaryExpression TypeIs (System.Linq.Expressions.Expression expression, Type type);
static member TypeIs : System.Linq.Expressions.Expression * Type -> System.Linq.Expressions.TypeBinaryExpression
Public Shared Function TypeIs (expression As Expression, type As Type) As TypeBinaryExpression

参数

expression
Expression

要将 Expression 属性设置为与其相等的 Expression

type
Type

要将 Type 属性设置为与其相等的 TypeOperand

返回

一个 TypeBinaryExpression,其 NodeType 属性等于 TypeIs 并且 ExpressionTypeOperand 属性设置为指定值。

例外

expressiontypenull

示例

以下示例演示如何使用 TypeIs(Expression, Type) 方法创建一个 TypeBinaryExpression ,该测试表示针对类型的 Int32 字符串值的类型测试。

// Create a TypeBinaryExpression that represents a
// type test of the string "spruce" against the 'int' type.
System.Linq.Expressions.TypeBinaryExpression typeBinaryExpression =
    System.Linq.Expressions.Expression.TypeIs(
        System.Linq.Expressions.Expression.Constant("spruce"),
        typeof(int));

Console.WriteLine(typeBinaryExpression.ToString());

// This code produces the following output:
//
// ("spruce" Is Int32)
' Create a TypeBinaryExpression that represents a
' type test of the String "spruce" against the Int32 type.
Dim typeBinaryExpression As System.Linq.Expressions.TypeBinaryExpression = _
    System.Linq.Expressions.Expression.TypeIs( _
        System.Linq.Expressions.Expression.Constant("spruce"), _
        Type.GetType("System.Int32"))

Console.WriteLine(typeBinaryExpression.ToString())

' This code produces the following output:
'
' ("spruce" Is Int32)

注解

Type生成的 UnaryExpression 的 属性表示 Boolean

适用于