我正在我的代码中构建一个工作流程,我不知道如何添加简单(While)条件。试图找出如何,但没有运气,在互联网上搜索,但也没有运气。
这是我想要做的简化版本:
ActivityBuilder ab = new ActivityBuilder();
ab.Implementation = new Sequence()
{
Variables =
{
new Variable<int>("StepNo", 0)
},
Activities =
{
new While()
{
Condition = <the_condition>
Body =
{
//Some logic here and the StepNo is increased
}
}
}
}
While条件应该类似于“StepNo&lt; 10”。不知道怎么能这样做?
答案 0 :(得分:4)
var stepNo = new Variable<int>("stepNo", 0);
var activity = new Sequence
{
Variables =
{
stepNo
},
Activities =
{
new While
{
Condition = new LessThan<int,int,bool>
{
Left = stepNo,
Right = 10
},
Body = new Sequence
{
Activities =
{
new Assign<int>
{
To = stepNo,
Value = new Add<int, int, int>
{
Left = stepNo,
Right = 1
}
},
new WriteLine
{
Text = new VisualBasicValue<string>("\"Step: \" & stepNo")
}
}
}
}
}
};
或者没有expression activities但只有VisualBasicValue的版本,这也是一项活动:
var stepNo = new Variable<int>("stepNo", 0);
var activity = new Sequence
{
Variables =
{
stepNo
},
Activities =
{
new While
{
Condition = new VisualBasicValue<bool>("stepNo < 10"),
Body = new Sequence
{
Activities =
{
new Assign<int>
{
To = stepNo,
Value = new VisualBasicValue<int>("stepNo + 1")
},
new WriteLine
{
Text = new VisualBasicValue<string>("\"Step: \" & stepNo")
}
}
}
}
}
};