am new to Windows Workflow [WF], and interested in evaluating WF for business purposes. I decided to work through an introduction
[TestMethod]
public void TestMethod ()
{
TextWriter writer = new StringWriter ();
Sequence sequence = new Sequence
{
Activities =
{
// so, assigning a reference type [eg StringWriter]
// as target is prohibited in WF4RC. what or how do
// i assign a target? introduction cited above may
// not be current [ie may be Beta2, not RC] so ... ?
new WriteLine { Text = "Hello", TextWriter = writer },
new WriteLine { Text = "World", TextWriter = writer }
}
};
// !!! BLOWS UP !!!
WorkflowInvoker.Invoke (sequence);
}
and encountered
Test method SomeTests.SomeTests.TestMethod threw exception: System.Activities.InvalidWorkflowException: The following errors were encountered while processing the workflow tree: 'Literal': Literal only supports value types and the immutable type System.String. The type System.IO.TextWriter cannot be used as a literal.
Poking around, I found this article describing what appears to be the error I see above.
Being new to WF, I do not really understand the change or prescribed method to work around it. So, my question is,
With WF4RC, how does one [correctly] use WriteLine
activity?
Ack, k, so mental note: Attempt all permutations of a Google search. Found this after searching for
WriteLine activity WF RC
The solution is to wrap it in a LambdaValue<T>
, comme ca
[TestMethod]
public void TestMethod ()
{
StringWriter writer = new StringWriter ();
Sequence sequence = new Sequence
{
Activities =
{
new WriteLine
{
Text = "Hello",
TextWriter = new LambdaValue<TextWriter> (n => writer)
},
new WriteLine
{
Text = "World",
TextWriter = new LambdaValue<TextWriter> (n => writer)
}
}
};
WorkflowInvoker.Invoke (sequence);
Assert.
AreEqual (
"Hello\r\nWorld\r\n",
writer.GetStringBuilder ().ToString ());
}
which seems weird to me, but I am literally the opposite of "expert" :P
I would still welcome alternatives if anyone has them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With