如果InvokeMethod活动返回一个对象,如何在工作流中分配变量?

时间:2017-01-04 15:41:26

标签: c#-6.0 workflow-foundation-4.5

我在Windows Workflow Foundation中有一个InvokeMethod活动。这个工作流程非常简单:

  1. 向用户询问他/她的身高
  2. 如果身高超过5.9,则询问他/她的个人资料详情
  3. 显示个人资料详情
  4. 为实现这一目标,我创建了一个工作流程,如下所示: enter image description here

    如何将从InvokeMethod返回的对象指定为变量?

    我已发布my code on GitHub

1 个答案:

答案 0 :(得分:1)

以下是Visual Studio属性中的解决方案:

首先在工作流程中添加一个变量:

Printscreen workflow's variables

将InvokeMethod活动放入工作流工作区和 编辑属性:

PrintScreen (Properties of InvokeMethod)

  1. MethodName:输入您的MethodName
  2. 参数:设置参数(方向:输入,输入: typeNeeded ,值 yourValue
  3. 结果:输入先前定义的工作流程中的变量名称
  4. TargetType:设置方法返回的类型
  5. 以下是XAMLX中的解决方案

    xmlns:mca="clr-namespace:Microsoft.CSharp.Activities;assembly=System.Activities"
    xmlns:p1="http://schemas.microsoft.com/netfx/2009/xaml/activities"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    xmlns:sap2010="http://schemas.microsoft.com/netfx/2010/xaml/activities/presentation"
    
    <p1:InvokeMethod sap2010:WorkflowViewState.IdRef="InvokeMethod_1" MethodName="YourMethodName" TargetType="x:Object">
        <p1:InvokeMethod.Result>
            <p1:OutArgument x:TypeArguments="x:Object">
                <mca:CSharpReference x:TypeArguments="x:Object">workflowVariableName</mca:CSharpReference>
            </p1:OutArgument>
        </p1:InvokeMethod.Result>
        <p1:InArgument x:TypeArguments="x:Int32">
            <mca:CSharpValue x:TypeArguments="x:Int32">variableNamePassedToMyMethod;</mca:CSharpValue>
        </p1:InArgument>
    </p1:InvokeMethod>