声明变量<T>Windows 工作流 4.0 中 CodeActivity 中的变量 [英] Declare Variable&lt;T&gt; variable in a CodeActivity in windows workflow 4.0

查看:23
本文介绍了声明变量<T>Windows 工作流 4.0 中 CodeActivity 中的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Windows 工作流的新手,并试图了解变量,以下代码给了我一个错误 -

I am new to windows workflow and trying to get my head round variables, the following code gives me an error -

public sealed class CodeActivity1 : CodeActivity
{
    Variable<int> wfVar = new Variable<int>("wfVar", 0);

    protected override void Execute(CodeActivityContext context)
    {
        wfVar.Set(context, 1);
    }
}

不能使用类型为System.Int32"的变量wfVar".请确保它在 Activity 或 SymbolResolver 中声明.

考虑到我已经在 Activity 中声明了变量,错误是什么意思.

What does the error mean, considering that I have declared the variable in an Activity.

谢谢,伊利亚斯

推荐答案

如果您尝试使用 Variable 作为 CodeActivity 实现变量,那您就错了.CodeActivity 主要用于执行一些代码(当然在 Execute() 方法中),快速,退出.

If you're trying to use a Variable as a CodeActivity implementation variable, you're thinking it wrong. CodeActivity should be used mostly to execute some code (within Execute() method of course), quickly, and exit.

你想做的事只能通过NativeActivity来实现.通过这种方式,执行引擎知道存在一个可以在整个活动执行过程中使用(获取或设置)的变量.

What you want to do can be only achieved with NativeActivity. This way execution engine is aware of the existence of a variable that can be used (getted or setted) all over the activity execution.

public sealed class CustomActivity : NativeActivity
{
    Variable<int> wfVar = new Variable<int>("wfVar", 0);

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        base.CacheMetadata(metadata);

        metadata.AddImplementationVariable(wfVar);
    }

    protected override void Execute(CodeActivityContext context) 
    {
        wfVar.Set(context, 1);
    }
}

这篇关于声明变量<T>Windows 工作流 4.0 中 CodeActivity 中的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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