Freigeben über


Expression.TypeIs Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Namespace:  System.Linq.Expressions
Assembly:  System.Core (in System.Core.dll)

Syntax

'Declaration
Public Shared Function TypeIs ( _
    expression As Expression, _
    type As Type _
) As TypeBinaryExpression
public static TypeBinaryExpression TypeIs(
    Expression expression,
    Type type
)

Parameters

Return Value

Type: System.Linq.Expressions.TypeBinaryExpression
A TypeBinaryExpression for which the NodeType property is equal to TypeIs and for which the Expression and TypeOperand properties are set to the specified values.

Exceptions

Exception Condition
ArgumentNullException

expression or type is nulla null reference (Nothing in Visual Basic).

Remarks

The Type property of the resulting UnaryExpression represents Boolean.

Examples

The following example demonstrates how to use the TypeIs(Expression, Type) method to create a TypeBinaryExpression that represents a type test of a string value against the Int32 type.

' 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"))

outputBlock.Text &= typeBinaryExpression.ToString() & vbCrLf

' This code produces the following output:
'
' ("spruce" Is 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));

outputBlock.Text += typeBinaryExpression.ToString() + "\n";

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

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.