本文整理汇总了C#中System.Activities.DynamicActivity类的典型用法代码示例。如果您正苦于以下问题:C# DynamicActivity类的具体用法?C# DynamicActivity怎么用?C# DynamicActivity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DynamicActivity类属于System.Activities命名空间,在下文中一共展示了DynamicActivity类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DynamicActivity
// Variables
var iterationVariable = new DelegateInArgument<int>() { Name = "iterationVariable" };
var accumulator = new Variable<int>() { Default = 0, Name = "accumulator" };
// Define the Input and Output arguments that the DynamicActivity binds to
var numbers = new InArgument<List<int>>();
var average = new OutArgument<double>();
var result = new Variable<double>() { Name = "result" };
return new DynamicActivity()
{
DisplayName = "Find average",
Properties =
{
// Input argument
new DynamicActivityProperty
{
Name = "Numbers",
Type = typeof(InArgument<List<int>>),
Value = numbers
},
// Output argument
new DynamicActivityProperty
{
Name = "Average",
Type = typeof(OutArgument<double>),
Value = average
}
},
Implementation = () =>
new Sequence
{
Variables = { result, accumulator },
Activities =
{
new ForEach<int>
{
Values = new ArgumentValue<IEnumerable<int>> { ArgumentName = "Numbers" },
Body = new ActivityAction<int>
{
Argument = iterationVariable,
Handler = new Assign<int>
{
To = accumulator,
Value = new InArgument<int>(env => iterationVariable.Get(env) + accumulator.Get(env))
}
}
},
// Calculate the average and assign to the output argument.
new Assign<double>
{
To = new ArgumentReference<double> { ArgumentName = "Average" },
Value = new InArgument<double>(env => accumulator.Get(env) / numbers.Get(env).Count<int>())
},
}
}