简体   繁体   English

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

[英]How to assign a variable in a workflow if InvokeMethod activity returns an object?

I have an InvokeMethod Activity in Windows Workflow Foundation. 我在Windows Workflow Foundation中有一个InvokeMethod活动。 This workflow is quite simple: 这个工作流程非常简单:

  1. ask to user for his/her height 向用户询问他/她的身高
  2. if height is greater than 5.9, then ask his/her profile details 如果身高大于5.9,则询问他/她的个人资料详细信息
  3. display profile details 显示个人资料详细信息

To achieve this, I have created a workflow, seen below: 为此,我创建了一个工作流程,如下所示: 在此处输入图片说明

How can I assign an object which is return from InvokeMethod as variable? 如何分配从InvokeMethod返回的对象作为变量?

I have posted my code on GitHub . 我已将代码发布在GitHub上

Here is the solution within Visual Studio properties: 这是Visual Studio属性中的解决方案:

First add a variable to your workflow: 首先向您的工作流程添加一个变量:

打印屏幕工作流程的变量

Drop an InvokeMethod Activity into your workflow workspace and edit properties: 将InvokeMethod活动放入您的工作流工作区并编辑属性:

PrintScreen(InvokeMethod的属性)

  1. MethodName: Enter your MethodName 方法名称:输入您的方法名称
  2. Parameters: Set parameters (Direction: In, Type: typeNeeded , Value yourValue ) 参数:设置参数(方向:在,类型: typeNeeded ,值yourValue
  3. Result: Enter the variable name from your workflow defined earlier 结果:输入先前定义的工作流中的变量名称
  4. TargetType: Set the type of your method return's type TargetType:设置方法返回类型的类型

Here is the solution in XAMLX 这是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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM