This section describes how to use the principles and skills of parameters and variables in WF4.0.
Download this example:
Http://files.cnblogs.com/foundation/VariablesAndArgumentsSample.rar
Examples
Use of data transmission variables and parameters
[Parameters] can be bound to [variables] in [expression mode ].
[In parameter]. The value of the correlated variable can be passed In. When the parameter is modified internally, the correlated variable is not changed.
Note:
1. Define a [InChangeActivity] with a string type [In parameter] myIn
Print the value of myIn in the [Execute] method, modify the value of myIn, and then print again
2. Add a string [myVariable] variable to the xaml workflow.
3. Add a [Assign] In the xaml workflow to Assign a value to the [myVariable] variable.
4. Add [InChangeActivity] and [InChangeActivity. myIn] To The xaml workflow and bind them to the [myVariable] variable.
5. Add [WriteLine] To The xaml workflow and print the variable value of [myVariable ].
|
InChangeActivity |
Public sealed class InChangeActivity: CodeActivity
{
Public InArgument <string> myIn {get; set ;}
Protected override void Execute (CodeActivityContext context)
{
String s1 = context. GetValue (this. myIn );
System. Console. WriteLine ("input value: a: {0}", s1 );
//
Context. SetValue (myIn, Guid. NewGuid (). ToString ());
//
String s2 = context. GetValue (this. myIn );
System. Console. WriteLine ("Internal modification: {0}", s2 );
}
} |
|
Workflow |
|
|
Host |
WorkflowInvoker. Invoke (new InChangeWorkflow ()); |
|
Result |
|
[Out parameter] The correlated variable value cannot be passed in. When an internal parameter is modified, the associated variable is updated.
Note:
1. Define an [OutChangeActivity] with a string type [Out parameter] myOut
Print the value of myOut in the [Execute] method, modify the value of myOut, and then print it again.
2. Add a string [myVariable] variable to the xaml workflow.
3. Add a [Assign] In the xaml workflow to Assign a value to the [myVariable] variable.
4. Add [OutChangeActivity] and [OutChangeActivity. myOut] To The xaml workflow and bind them to the [myVariable] variable.
5. Add [WriteLine] To The xaml workflow and print the variable value of [myVariable ].
|
OutChangeActivity |
Public sealed class OutChangeActivity: CodeActivity
{
Public OutArgument <string> myOut {get; set ;}
Protected override void Execute (CodeActivityContext context)
{
String s1 = context. GetValue (this. myOut );
System. Console. WriteLine ("input value: {0}", s1 );
//
Context. SetValue (myOut, Guid. NewGuid (). ToString ());
//
String s2 = context. GetValue (this. myOut );
System. Console. WriteLine ("Internal modification: {0}", s2 );
}
} |
|
Workflow |
|
|
Host |
WorkflowInvoker. Invoke (new OutChangeWorkflow ()); |
|
Result |
|
The value of the [In/Out parameter] correlated variable can be passed In. When the internal parameter is modified, the associated variable is updated.
Note:
1. Define a [InOutChangeActivity] with a string type [InOut parameter] myInOut
Print the value of myInOut in the [Execute] method, modify the value of myInOut, and print again
2. Add a string [myVariable] variable to the xaml workflow.
3. Add a [Assign] In the xaml workflow to Assign a value to the [myVariable] variable.
4. Add [InOutChangeActivity] and [InOutChangeActivity. myInOut] To The xaml workflow and bind them to the [myVariable] variable.
5. Add [WriteLine] To The xaml workflow and print the variable value of [myVariable ].
|
InOutChangeActivity |
Public sealed class InOutChangeActivity: CodeActivity
{
Public InOutArgument <string> myInOut {get; set ;}
Protected override void Execute (CodeActivityContext context)
{
String s1 = context. GetValue (this. myInOut );
System. Console. WriteLine ("input value: a: {0}", s1 );
//
Context. SetValue (myInOut, Guid. NewGuid (). ToString ());
//
String s2 = context. GetValue (this. myInOut );
System. Console. WriteLine ("Internal modification: {0}", s2 );
}
} |
|
Workflow |
|
|
Host |
WorkflowInvoker. Invoke (new InOutChangeWorkflow ()); |
|
Result |
|