2012-03-28 40 views
0

我正在使用Windows Workflow Foundation开发一个c#项目。我正在编写一些自定义活动,而我没有使用设计器。我将下面的代码分配给一个活动的局部变量。如何在while活动内部访问StepNo的值?请帮忙吗?c#工作流变量

While wfWhile = new While(); 

//temporary Assign activity, remove it later 
Variable<int> stepNo = new Variable<int>("stepNo", 0); 

wfWhile.Variables.Add(stepNo); 

回答

0

不同的方式做到这一点,但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);