WF4.0 BASICS (20) ActivityWithResult returned value Activity

Source: Internet
Author: User

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

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.