ExpressionServices 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
환경 인식 식을 작업 트리로 변환하는 데 사용되는 변환 API입니다.
public ref class ExpressionServices abstract sealed
public static class ExpressionServices
type ExpressionServices = class
Public Class ExpressionServices
- 상속
-
ExpressionServices
예제
다음 코드 예제에서는 인덱스 0의 배열 요소와 인덱스 1의 배열 요소의 합계를 계산하기 위해 호출 Convert 합니다. 다음으로 결과 합계가 변수에 할당되고 콘솔에 출력됩니다.
public static void ComputeSumWithConvert()
{
var arrayvar = new Variable<int[]>("arrayvar", new int[] { 1, 2 });
var intvar = new Variable<int>("intvar");
// Use ExpressionServices.Convert() to convert the composite lambda expression
// that represents the sum of array elements at index 0 and 1.
Activity<int> activity1 = ExpressionServices.Convert<int>(ctx => arrayvar.Get(ctx)[0] + arrayvar.Get(ctx)[1]);
Activity seq = new Sequence
{
Variables = { arrayvar, intvar },
Activities =
{
// Get the sum value.
new Assign<int>
{
To = intvar,
Value = activity1,
},
// Print the sum value of 3 to the console.
new WriteLine
{
Text = new InArgument<string>(ctx => intvar.Get(ctx).ToString()),
},
}
};
WorkflowInvoker.Invoke(seq);
}
다음 코드 예제는 비교를 위해 제공됩니다. 이 두 번째 예제에서는 식 작업을 인스턴스화하여 합계를 Add<TLeft,TRight,TResult> 계산하는 방법을 보여줍니다. 두 예제는 기능적으로 동일하지만 두 번째 방법은 더 많은 코딩을 포함하며 호출 Convert만큼 간단하지 않습니다. 따라서 첫 번째 예제를 사용하는 것이 좋습니다.
public static void ComputeSumWithExpressionActivity()
{
var arrayvar = new Variable<int[]>("arrayvar", new int[] { 1, 2 });
var intvar = new Variable<int>("intvar");
// Create an Add activity to compute the sum of array elements at index 0 and 1.
Activity<int> activity1 = new Add<int, int, int>
{
Left = new ArrayItemValue<int>
{
Array = arrayvar,
Index = 0,
},
Right = new ArrayItemValue<int>
{
Array = arrayvar,
Index = 1,
}
};
Activity seq = new Sequence
{
Variables = { arrayvar, intvar },
Activities =
{
// Get the sum value.
new Assign<int>
{
To = intvar,
Value = activity1,
},
// Print the sum value of 3 to the console.
new WriteLine
{
Text = new InArgument<string>(ctx => intvar.Get(ctx).ToString()),
},
}
};
WorkflowInvoker.Invoke(seq);
}
설명
이 클래스의 변환 메서드는 여러 하위 식을 포함할 수 있는 지정된 람다 식을 작업 계층 구조로 구성된 활동 트리로 변환합니다. 더 높은 수준의 추상화를 제공하고 워크플로를 보다 직관적으로 구현할 수 있으므로 식 활동을 직접 인스턴스화하는 대신 이러한 변환 메서드를 사용하는 것이 좋습니다. 자세한 내용은 예제를 참조하세요.
변환 메서드 ExpressionServices 는 워크플로 내에서 정의되거나 인수를 통해 워크플로에 전달되는 변수 및 상수와 함께 작동하도록 설계되었습니다.
메서드
| Name | Description |
|---|---|
| Convert<TResult>(Expression<Func<ActivityContext,TResult>>) |
워크플로 환경 인식 식을 작업 트리로 변환합니다. |
| ConvertReference<TResult>(Expression<Func<ActivityContext,TResult>>) |
워크플로 환경 인식 식에 대한 참조를 작업 트리로 변환합니다. |
| TryConvert<TResult>(Expression<Func<ActivityContext,TResult>>, Activity<TResult>) |
워크플로 환경 인식 식을 작업 트리로 변환합니다. |
| TryConvertReference<TResult>(Expression<Func<ActivityContext,TResult>>, Activity<Location<TResult>>) |
워크플로 환경 인식 식에 대한 참조를 작업 트리로 변환합니다. |