Confusion over the <T> argument and the <T> variable in the .NET 4.0 Workflow Foundation
I am using Windows Workflow Foundation in .NET 4.0. The following is the syntax / semantic confusion.
I have 2 equivalent ways to declare an Assign operation to assign a value to a workflow variable (varIsFreeShipping).
(1) Using XAML in the designer.
(2) Use of code.
But in approach 2, it seems that I'm creating a new OutArgument <Boolean> and assign it a value, not the original Variable <Boolean> varIsFreeShipping. And OutArgument and Variable are completely different types.
So how does the value assigned to this new argument finally reach the original variable?
This pattern seems common in WF 4.0. Can anyone shed some light on this?
Thanks!
In fact, the second (2) method can be written in the same way as:
Then = new Assign<bool> { To = varIsFreeShipping, Value = true }
This all works because OutArgument <t> can be initialized with Variable <T> using an implicit statement .
In the first (1) appointment, using the editor, what happens behind the scenes; the variable is implicitly converted from the variable to OutArgument.
WF4 uses many implicit operators, mainly for Activity <T> from / to variable <T>, OutArgument <T> from / to variable <T>, etc. If you look at it, they all represent a piece of data (already evaluated or not) that is located somewhere. This is exactly the same as in C #, for example:
public int SomeMethod(int a) { var b = a; return a; }
You can assign an argument to a variable, but you can also return the same variable as the out argument. This is what you do with this Assign <T> (using the varIsFreeShipping variable as an activity argument).
Does this answer your question?