2012-03-28 53 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);