Expression.Convert 메서드

정의

형식 변환 연산을 나타내는 UnaryExpression을 만듭니다.

오버로드

Convert(Expression, Type)

형식 변환 연산을 나타내는 UnaryExpression을 만듭니다.

Convert(Expression, Type, MethodInfo)

구현 메서드가 지정된 변환 연산을 나타내는 UnaryExpression을 만듭니다.

Convert(Expression, Type)

형식 변환 연산을 나타내는 UnaryExpression을 만듭니다.

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

매개 변수

expression
Expression

Expression 속성에 설정할 Operand입니다.

type
Type

Type 속성에 설정할 Type입니다.

반환

UnaryExpression

UnaryExpression 속성이 NodeType이고 ConvertOperand 속성이 지정된 값으로 설정된 Type입니다.

예외

expression 또는 typenull인 경우

expression.Type과 type 사이에 변환 연산자가 정의되지 않은 경우

예제

다음 코드 예제에서는 형식 변환 작업을 나타내는 식을 만드는 방법을 보여 줍니다.

// Add the following directive to your file:
// using System.Linq.Expressions;

// This expression represents a type conversion operation.
Expression convertExpr = Expression.Convert(
                            Expression.Constant(5.5),
                            typeof(Int16)
                        );

// Print out the expression.
Console.WriteLine(convertExpr.ToString());

// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda<Func<Int16>>(convertExpr).Compile()());

// This code example produces the following output:
//
// Convert(5.5)
// 5
' Add the following directive to your file:
' Imports System.Linq.Expressions 

' This expression represents a type conversion operation.        
Dim convertExpr As Expression = Expression.Convert(
                            Expression.Constant(5.5),
                            GetType(Int16)
                        )

' Print the expression.
Console.WriteLine(convertExpr.ToString())

' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda(Of Func(Of Int16))(convertExpr).Compile()())

' This code example produces the following output:
'
' Convert(5.5)
' 5

설명

Method 결과 UnaryExpression 속성은 구현 메서드로 설정됩니다. IsLiftedToNull 속성은 false입니다. 노드가 해제되면 IsLifted .입니다 true. 그렇지 않으면 false입니다.

구현 방법

다음 규칙은 작업에 대한 구현 방법을 결정합니다.

  • 둘 중 하나이 expression면 . 형식이거나 type 암시적 또는 명시적 변환 연산자를 정의하는 사용자 정의 형식으로, MethodInfo 해당 연산자가 구현 메서드임을 나타냅니다.

  • 그렇지 않은 경우:

    • 둘 다 expression인 경우 . type 숫자 또는 부울 형식 또는 nullable 또는 nullable이 아닌 열거형 형식을 입력하고 나타내면 구현 메서드가 있습니다 null.

    • 둘 중 하나이 expression면 . 형식 또는 type 참조 형식이며 명시적 boxing, unboxing 또는 참조 변환이 expression있습니다. 형식을 지정합니다 type. 구현 메서드는 .입니다 null.

해제됨 및 해제되지 않은 경우

구현 메서드가 아닌 null경우:

  • If expression. 형식은 구현 메서드의 인수 형식에 할당할 수 있으며 구현 메서드의 반환 형식을 할당할 type수 있으며 노드는 해제되지 않습니다.

  • 둘 중 하나 또는 둘 다인 expression경우 형식 또는 type nullable 값 형식이며 해당 nullable이 아닌 값 형식은 각각 구현 메서드의 인수 형식 및 반환 형식과 같으며 노드가 해제됩니다.

구현 방법이 다음과 같은 경우:null

  • 둘 다 expression인 경우 . type nullable이 아닌 형식이며 노드가 해제되지 않습니다.

  • 그렇지 않으면 노드가 해제됩니다.

적용 대상

Convert(Expression, Type, MethodInfo)

구현 메서드가 지정된 변환 연산을 나타내는 UnaryExpression을 만듭니다.

public:
 static System::Linq::Expressions::UnaryExpression ^ Convert(System::Linq::Expressions::Expression ^ expression, Type ^ type, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.UnaryExpression Convert (System.Linq.Expressions.Expression expression, Type type, System.Reflection.MethodInfo method);
public static System.Linq.Expressions.UnaryExpression Convert (System.Linq.Expressions.Expression expression, Type type, System.Reflection.MethodInfo? method);
static member Convert : System.Linq.Expressions.Expression * Type * System.Reflection.MethodInfo -> System.Linq.Expressions.UnaryExpression
Public Shared Function Convert (expression As Expression, type As Type, method As MethodInfo) As UnaryExpression

매개 변수

expression
Expression

Expression 속성에 설정할 Operand입니다.

type
Type

Type 속성에 설정할 Type입니다.

method
MethodInfo

MethodInfo 속성에 설정할 Method입니다.

반환

UnaryExpression

UnaryExpression 속성이 NodeType이고 Convert, OperandType 속성이 지정된 값으로 설정된 Method입니다.

예외

expression 또는 typenull인 경우

methodnull이 아니고 이것이 나타내는 메서드가 void를 반환하거나, static(Visual Basic의 경우 Shared)이 아니거나, 정확하게 하나의 인수를 사용하지 않는 경우

expression.Type과 type 사이에 변환 연산자가 정의되지 않은 경우

또는 expression.Type을 method가 나타내는 메서드의 인수 형식에 할당할 수 없는 경우

또는 method가 나타내는 메서드의 반환 형식을 type에 할당할 수 없는 경우

또는 expression.Type 또는 type이 nullable 값 형식이고 nullable이 아닌 해당 값 형식이 method가 나타내는 메서드의 인수 형식 또는 반환 형식과 각각 일치하지 않는 경우

method 설명과 일치하는 메서드가 둘 이상 있는 경우

설명

Method 결과 UnaryExpression 속성은 구현 메서드로 설정됩니다. IsLiftedToNull 속성은 false입니다. 노드가 해제되면 IsLifted .입니다 true. 그렇지 않으면 false입니다.

구현 방법

다음 규칙은 작업에 대한 구현 방법을 결정합니다.

  • 메서드가 아닌 null경우 구현 메서드입니다. 인수 하나를 사용하는 void static 가 아닌 메서드(SharedVisual Basic)를 나타내야 합니다.

  • 그렇지 않으면 expression. 형식이거나 type 암시적 또는 명시적 변환 연산자를 정의하는 사용자 정의 형식으로, MethodInfo 해당 연산자가 구현 메서드임을 나타냅니다.

  • 그렇지 않은 경우:

    • 둘 다 expression인 경우 . type 숫자 또는 부울 형식 또는 nullable 또는 nullable이 아닌 열거형 형식을 입력하고 나타내면 구현 메서드가 있습니다 null.

    • 둘 중 하나이 expression면 . 형식 또는 type 참조 형식이며 명시적 boxing, unboxing 또는 참조 변환이 expression있습니다. 형식을 지정합니다 type. 구현 메서드는 .입니다 null.

해제됨 및 해제되지 않은 경우

구현 메서드가 아닌 null경우:

  • If expression. 형식은 구현 메서드의 인수 형식에 할당할 수 있으며 구현 메서드의 반환 형식을 할당할 type수 있으며 노드는 해제되지 않습니다.

  • 둘 중 하나 또는 둘 다인 expression경우 형식 또는 type nullable 값 형식이며 nullable이 아닌 해당 값 형식은 각각 구현 메서드의 인수 형식 및 반환 형식과 같으며 노드가 해제됩니다.

구현 방법이 다음과 같은 경우:null

  • 둘 다 expression인 경우 . type nullable이 아닌 형식이며 노드가 해제되지 않습니다.

  • 그렇지 않으면 노드가 해제됩니다.

적용 대상