简体   繁体   English

在Workflow Foundation 4.0中,如何在声明了Activity的Execute方法之外读取InArgument的值?

[英]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.

相关问题 Workflow Foundation-在Custom Designer中分配InArgument - Workflow Foundation - Assign InArgument in Custom Designer 如何获取已传递给方法的类 - how can I get which class has been passed to method Windows工作流基础4.0(WPF):如何通过代码更改流程图工作流中的活动位置 - Window workflow foundation 4.0 (WPF): How to change an activity location in a Flowchart workflow by code 如何从已声明为接口的基类中获取值? - How Can I get a value from a base class that has been declared as an Interface? 如何对Windows Workflow Foundation(WF)活动可以序列化进行单元测试? - How to unit test that a Windows Workflow Foundation (WF) activity can be serialized? 如何仅在XtraInputBox中接受数字值,如何检查单击了哪个按钮? - How to accept only numeric value in XtraInputBox and how can I check which button has been clicked? Workflow Foundation 4.5如何在异常情况下重复活动 - Workflow Foundation 4.5 How to repeat activity on exception CRM 4.0-自定义工作流活动,能够检查属性值是否已更改 - CRM 4.0 - Custom workflow activity that is able to check whether an attribute's value has changed 如何在Main()中使用方法(其参数已由ref传递)的返回值 - How can I use a method's (whose argument has been passed by ref) return value in Main() Windows Workflow Foundation 4.0连接器 - Windows Workflow Foundation 4.0 connector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM