像参数WF4一样传递控制

时间:2014-10-07 18:21:23

标签: c# workflow-foundation-4

我试图传递一个复杂的对象ScriptControl,作为工作流的In参数。我得到的错误是:

`The following errors were encountered while processing the workflow tree:
'Literal<ScriptControl>': Literal only supports value types and the immutable type     System.String.  The type ScriptDisplay.ScriptControlcannot be used as a literal.`

我是工作流程的新手,我了解问题,但如何解决?

1 个答案:

答案 0 :(得分:1)

没有看到你的代码,我无法确定,但这通常是由使用WorkflowInvoker引起的。 e.g。

WorkflowInvoker.Invoke(workflow,ScriptControl)

这样做的方法是将复杂的对象放入字典中。

ScriptControl scriptControl= new ScriptControl{ initialise your object here };

Dictionary<string, object> inputDictionary = new Dictionary<string, object> { { "ScriptControl", scriptControl } };

var output = WorkflowInvoker.Invoke(workflow, inputDictionary );

然后像往常一样使用字典来访问scriptControl对象。

e.g。

var x = dictionary["ScriptControl"].some property of your ScriptControl object

Ron Jacobs talks more about this here