public sealed class Parent : NativeActivity
{
public Parent()
{
Childrens = new Collection<Activity>();
Variables = new Collection<Variable>();
_currentActivityIndex = new Variable<int>();
CurrentCustomTypeInstance= new Variable<MyCustomType>();
}
[Browsable(false)]
public Collection<Activity> Childrens { get; set; }
protected override void Execute(NativeActivityContext context)
{
_currentActivityIndex.Set(context, 0);
context.ScheduleActivity(FirstActivity, Callback);
}
private void Callback(NativeActivityContext context, ActivityInstance completedInstance, MyCustomType customTypeInstance)
{
CurrentCustomTypeInstance.Set(context, customTypeInstance);
ScheduleNextChildren(context, completedInstance);
}
private void ScheduleNextChildren(NativeActivityContext context, ActivityInstance completedInstance)
{
int nextActivityIndex = _currentActivityIndex.Get(context) + 1;
if (nextActivityIndex >= Childrens.Count)
return;
Activity nextActivity = Childrens[nextActivityIndex];
IFoo nextActivityAsIFoo = nextActivity as IFoo;
if (nextActivityAsIFoo != null)
{
var currentCustomTypeInstance = CurrentCustomTypeInstance.Get(context);
// HERE IS MY EXCEPTION
nextActivityAsIFoo.FooField.Set(context, currentCustomTypeInstance);
}
context.ScheduleActivity(nextActivity);
_currentActivityIndex.Set(context, nextActivityIndex);
}
}
在寄存器元数据中:
metadata.SetChildrenCollection(Childrens);
我已经阅读了http://msmvps.com/blogs/theproblemsolver/archive/2011/04/05/scheduling-child-activities-with-input-parameters.aspx但就我而言,父母不知道孩子的活动
编辑
Activity '1.1: Parent' cannot access this variable because it is declared at the scope
of activity '1.1: Parent'. An activity can only access its own implementation variables.
但在我的情况下,我不需要获得返回值,所以,希望更容易。只需要隐式传递 FooField 而不是让它流向作者。我需要隐含地做到这一点!如果它根本不起作用,我将使用 NativeActivityContext Properties