This section describes how to use a returned value Activity in WF4.
Download this example:
Http://files.cnblogs.com/foundation/ActivityWithResultSample.rar
Examples
ActivityWithResult
Class Name |
System. Activities. ActivityWithResult |
File |
System. Activities. dll |
Structure Description |
Inherit Activity
Is A Pair Ace class
[Result] The attribute type is [System. Activities. OutArgument]
[ResultType] the attribute Type is [System. Type] |
Function Description |
[Result] attribute is returned value
[ResultType] attribute is returned value type
Derived class System. Activities. Activity <TResult>
Failed from System. activities. activity <TResult> implements custom Activity, because Activity <TResult> does not provide [Execute method], and [InternalExecute method is internal sealed] (For details, refer to [Activity execution principle])
From
CodeActivity <TResult>
NativeActivity <TResult>
AsycCodeActivity <TResult>
Implement custom Activity |
CodeActivity <TResult>
Return the value to the [Result] attribute using the override [Execute method] method Return Value
For example, Scenario Description: There are two [Int] parameters x and y. the return value is x + y.
Activity |
Public Sealed Class MyCodeActivity: CodeActivity <int>
{
Public InArgument <int> X {get; set ;}
Public InArgument <int> Y {get; set ;}
Protected Override Int Execute (CodeActivityContext context)
{
Int x = X. Get (context );
Int y = Y. Get (context );
Return x + y;
// ----- Or ---------
// Context. SetValue (base. Result, x + y );
// Return base. Result. Get (context );
}
} |
Workflow |
|
Host |
WorkflowInvoker. Invoke (new MyCodeActivityWorkflow ());
|
Result |
|
NativeActivity <TResult>
Implemented by assigning values to the [Result] attribute
For example, Scenario Description: There are two [Int] parameters x and y. the return value is x + y.
Activity |
Public Sealed Class MyNativeActivity: NativeActivity <int>
{
Public System. Activities. InArgument <int> x
{Set; get ;}
Public System. Activities. InArgument <int> y
{Set; get ;}
Protected Override Void Execute (NativeActivityContext context)
{
Int r = (int) x. Get (context) + (int) y. Get (context );
This. Result. Set (context, r );
}
}
|
Workflow |
|
Host |
WorkflowInvoker. Invoke (new MyNativeActivityWorkflow ());
|
Result |
|