ConvertChecked Method (Expression, Type, MethodInfo)
Collapse the table of content
Expand the table of content

Expression::ConvertChecked Method (Expression^, Type^, MethodInfo^)

 

Creates a UnaryExpression that represents a conversion operation that throws an exception if the target type is overflowed and for which the implementing method is specified.

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

public:
static UnaryExpression^ ConvertChecked(
	Expression^ expression,
	Type^ type,
	MethodInfo^ method
)

Parameters

expression
Type: System.Linq.Expressions::Expression^

An Expression to set the Operand property equal to.

type
Type: System::Type^

A Type to set the Type property equal to.

method
Type: System.Reflection::MethodInfo^

A MethodInfo to set the Method property equal to.

Return Value

Type: System.Linq.Expressions::UnaryExpression^

A UnaryExpression that has the NodeType property equal to ConvertChecked and the Operand, Type, and Method properties set to the specified values.

Exception Condition
ArgumentNullException

expression or type is null.

ArgumentException

method is not null and the method it represents returns void, is not static (Shared in Visual Basic), or does not take exactly one argument.

InvalidOperationException

No conversion operator is defined between expression.Type and type.

-or-

expression.Type is not assignable to the argument type of the method represented by method.

-or-

The return type of the method represented by method is not assignable to type.

-or-

expression.Type or type is a nullable value type and the corresponding non-nullable value type does not equal the argument type or the return type, respectively, of the method represented by method.

AmbiguousMatchException

More than one method that matches the method description was found.

The Method property of the resulting UnaryExpression is set to the implementing method. The IsLiftedToNull property is false. If the node is lifted, IsLifted is true. Otherwise, it is false.

The following rules determine the implementing method for the operation:

  • If method is not null, it is the implementing method. It must represent a non-void, static (Shared in Visual Basic) method that takes one argument.

  • Otherwise, if either expression.Type or type is a user-defined type that defines an implicit or explicit conversion operator, the MethodInfo that represents that operator is the implementing method.

  • Otherwise:

    • If both expression.Type and type represent numeric or Boolean types, or nullable or non-nullable enumeration types, the implementing method is null.

    • If either expression.Type or type is a reference type and an explicit boxing, unboxing, or reference conversion exists from expression.Type to type, the implementing method is null.

If the implementing method is not null:

  • If expression.Type is assignable to the argument type of the implementing method and the return type of the implementing method is assignable to type, the node is not lifted.

  • If either or both of expression.Type or type are a nullable value type and the corresponding non-nullable value types are equal to the argument type and the return type of the implementing method respectively, the node is lifted.

If the implementing method is null:

  • If both expression.Type and type are non-nullable, the node is not lifted.

  • Otherwise the node is lifted.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
Show:
© 2016 Microsoft