[英]How can I, in Workflow Foundation 4.0, read the value of an InArgument outside of the Execute method of the Activity in which it has been declared?
How do I access or read the value of an InArgument outside of the Execute method of the Activity in which it has been declared? 如何在声明了Activity的Execute方法的外部访问或读取InArgument的值?
I tried invoking the get method by passing the NativeActivityContext, but that just resulted in getting a "declare the argument on the activity" message. 我尝试通过传递NativeActivityContext来调用get方法,但这只是导致获得“在活动中声明参数”消息。
Type t = typeof(System.Activities.InArgument<>).MakeGenericType(typeof(Test.Entities.Agent));
object obj = Activator.CreateInstance(t);
MethodInfo dd = t.GetMethod("Get");
object magic = dd.Invoke(obj, new object[] { (System.Activities.ActivityContext)context });
Not sure where your context comes from but it looks like it wasn't provided by the workflow runtime. 不确定上下文来自何处,但工作流运行时似乎未提供上下文。 The workflow runtime managers all arguments and variables for you and let you get at data through the NativeActivityContext.
工作流运行时为您管理所有参数和变量,并允许您通过NativeActivityContext获取数据。 These aren't types you can just use somewhere else they depend on the internal structures provided by the runtime.
这些不是您可以在其他地方使用的类型,它们取决于运行时提供的内部结构。 If you are trying to unit test an activity you should use the WorkflowInvoker to execute your activity.
如果要对活动进行单元测试,则应使用WorkflowInvoker来执行活动。 Use activity extensions to separate the activity, the intent, with the actual implementation, the extension.
使用活动扩展将活动,意图与实际的实现,扩展分开。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.