WF4RC,WriteLine活动引发的StringWriter的错误分配到的TextWriter分配、错误、WriteLine、WF4RC

2023-09-03 16:56:10 作者:绿柚

是新的Windows Workflow [WF],感兴趣的评估WF为经营宗旨。我决定通过介绍工作

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);
}

和遇到

测试方法SomeTests.SomeTests.TestMethod抛出异常:   System.Activities.InvalidWorkflowException:处理流程树下面遇到了错误:   '字面':文字仅支持值类型和不可变的System.String类型。类型System.IO.TextWriter不能用来作为文字

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.

作为新WF,我真的不明白这些改变或prescribed方法来解决它。所以,我的问题是,

Being new to WF, I do not really understand the change or prescribed method to work around it. So, my question is,

通过WF4RC,如何来[正确]使用的WriteLine 活动?

With WF4RC, how does one [correctly] use WriteLine activity?

推荐答案

确认,K,所以心里记:尝试了谷歌搜索的所有排列。找到this搜索后

Ack, k, so mental note: Attempt all permutations of a Google search. Found this after searching for

WriteLine活动WF RC

WriteLine activity WF RC

解决的办法是把它包在 LambdaValue< T> ,COMME CA

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 ());
}

这似乎怪​​我,但我字面意思是专家的反面:P

which seems weird to me, but I am literally the opposite of "expert" :P

我还是欢迎的替代品,如果任何人有他们。

I would still welcome alternatives if anyone has them.