【问题标题】:c# workflow variablec# 工作流变量
【发布时间】:2012-03-28 08:31:19
【问题描述】:
我正在使用 Windows Workflow Foundation 开发一个 c# 项目。我正在编写一些自定义活动,但我没有使用设计器。我有以下代码,我将其分配给局部变量一段时间的活动。如何在 while 活动中访问 StepNo 的值?有什么帮助吗?
While wfWhile = new While();
//temporary Assign activity, remove it later
Variable<int> stepNo = new Variable<int>("stepNo", 0);
wfWhile.Variables.Add(stepNo);
【问题讨论】:
标签:
c#
c#-4.0
workflow-foundation
workflow-foundation-4
【解决方案1】:
执行此操作的方式不同,但 VisualBasicValue<T> 是大多数时间执行此操作的方式。以下代码循环直到 stepNo 变为 10,打印 stepNo 的值并递增。
While wfWhile = new While();
Variable<int> stepNo = new Variable<int>("stepNo", 0);
wfWhile.Variables.Add(stepNo);
wfWhile.Body = new Sequence()
{
Activities = {
new WriteLine
{
Text = new VisualBasicValue<string>("\"Step: \" & stepNo ")
},
new Assign<int>()
{
To = new OutArgument<int>(stepNo),
Value= new VisualBasicValue<int>("stepNo + 1")
}
}
};
wfWhile.Condition = new VisualBasicValue<bool>("stepNo < 10");
WorkflowInvoker.Invoke(wfWhile);