具有 OutArgument 和分配活动的自定义 WF4 活动
我正在尝试通过编写标准活动来编写自定义活动,其中之一是分配活动,它负责将字符串值分配给名为“TextOut”的 OutArgument,我已在自定义活动中定义了该值。这个想法是,使用此自定义活动的工作流作者在工作流中定义一个变量,并将其映射到我的自定义活动的 TextOut OutArgument。我想通过迭代方法来实现这一点,因为我需要在运行时动态创建选择分支。我省略了这段代码以简化我的问题。
该活动的代码如下所示。这可能不是应该这样做的,因为它不起作用:)使用此活动的工作流程会引发验证错误:“未提供所需活动参数‘To’的值”。
我想获得一些有关如何让我的 OutArgument 与分配子活动一起工作的建议(因此无需在我的 OutArgument 上调用 .Set)。
public sealed class OutArgActivity : Activity
{
public OutArgument<string> TextOut { get; set; }
public OutArgActivity()
{
Assign assign = new Assign {
To = this.TextOut,
Value = new InArgument<string>(
env => "this is my custom return value")
};
Sequence sequence = new Sequence();
sequence.Activities.Add(assign);
this.Implementation = () => sequence;
}
}
I am trying to write a custom activity by composing standard Activities, one of which is an Assign activity which is responsible for assigning a string value to an OutArgument, called 'TextOut', which I have defined on my custom Activity. The idea is that the workflow author that uses this custom Activity defines a variable in the Workflow and maps this to the TextOut OutArgument of my custom Activity. I'd like to achieve this with an iterative approach, since I have a requirement to dynamically create pick branches at runtime. I have left out this code to simplify my question.
The code for the Activity is shown below. This is probably not how it should be done, since it doesn't work :) The workflow which uses this Activity throws a validation error: "Value for a required activity argument 'To' was not supplied".
I'd like to get some advice on how to get my OutArgument working with an Assign child activity (so without calling .Set on my OutArgument).
public sealed class OutArgActivity : Activity
{
public OutArgument<string> TextOut { get; set; }
public OutArgActivity()
{
Assign assign = new Assign {
To = this.TextOut,
Value = new InArgument<string>(
env => "this is my custom return value")
};
Sequence sequence = new Sequence();
sequence.Activities.Add(assign);
this.Implementation = () => sequence;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试在您的分配活动中使用 ArgumentReference,如下所示:
Try using a ArgumentReference in your Assign activity like this:
如果你不想使用魔法字符串,你可以这样做。
这似乎违反直觉,但由于
OutArgument<>
构造函数的参数是一个Expression
,因此可以将其转换为位置引用。这正是所发生的情况。If you don't want to use magic strings you can do it this way.
This seems counter intuitive, but since the argument to the constructor of
OutArgument<>
is anExpression
it is possible to convert it to a location reference. And that is exactly what happens.