共用方式為


Expression.TypeIs(Expression, Type) 方法

定義

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

適用於