如何在运行时构造的 VB 表达式中访问 Windows Workflow 中的变量 [英] How to access variables in Windows Workflow in VB expressions constructed at runtime

查看:22
本文介绍了如何在运行时构造的 VB 表达式中访问 Windows Workflow 中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我在尝试这样做时没有被误导,但我想在运行时为 Windows 工作流中的 InArgument 设置 VB 表达式,并让它访问当前范围内的变量.

特别是,我想将以下示例代码更改为 new VisualBasicValue("String.Format(\"Hello {0}\", FirstName) -也就是说,我想停止指定显式字符串World"并开始将名称从 Main 传递到工作流.我添加了一个名为 FirstName 的新 InArgument 到工作流本身,然后尝试按上述方式访问它,但它不起作用 - 我猜是因为它不知道 FirstName 在编译时指的是什么表达式.请问您知道实现相同目标的替代方法吗?

(这个问题的上下文是我正在编写代码来运行不同类型的计算.计算需要一个字符串参数,其中包含一个 VB 表达式,必须运行该表达式才能从各种不同位置之一获取一些数据. 我想在 .config 文件中为每种不同的计算类型指定 VB 表达式,然后在需要运行各种不同的计算时在运行时即时"评估这些表达式.)

使用 System.Activities;使用 Microsoft.VisualBasic.Activities;命名空间 SMG_RuntimeExpressionTest{课程计划{static void Main(string[] args){var wf = new Workflow();wf.Text = new VisualBasicValue("String.Format(\"Hello {0}\", \"World\")");WorkflowInvoker.Invoke(wf);}}}

解决方案

我有几篇关于参数的博文 WF4:向活动传递参数将参数传递给工作流活动(再次) 可能对您有所帮助.>

I hope I'm not being misguided in trying to do this, but I'd like to set the VB expression for an InArgument in Windows Workflow at runtime and have it access variables that are currently in scope.

In particular, I'd like to change the following bit of example code to say new VisualBasicValue<string>("String.Format(\"Hello {0}\", FirstName) - that is, I'd like to stop specifying the explicit string "World" and start passing in a name to the workflow from Main. I add a new InArgument called FirstName to the workflow itself, and then try and access it as above, but it doesn't work - I'm guessing because it doesn't know what FirstName is referring to at the point at which it compiles the expression. Please do you know of an alternative way to accomplish the same goal?

(The context for this problem is that I'm writing code to run different types of calculation. A calculation takes a string parameter that contains a VB expression that must be run to get some data from one of a variety of different locations. I want to specify the VB expression for each different calculation type in a .config file, then evaluate those expressions "on-the-fly" at runtime when it becomes necessary to run the various different calculations.)

using System.Activities;
using Microsoft.VisualBasic.Activities;

namespace SMG_RuntimeExpressionTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var wf = new Workflow();
            wf.Text = new VisualBasicValue<string>("String.Format(\"Hello {0}\", \"World\")");
            WorkflowInvoker.Invoke(wf);
        }
    }
}

解决方案

I've got a couple of blog posts on arguments WF4: Passing Arguments to Activities and Passing arguments to Workflow Activities (again) that might help you.

这篇关于如何在运行时构造的 VB 表达式中访问 Windows Workflow 中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆