wf4 一个活动只能访问自己的实现变量 [英] wf4 An activity can only access its own implementation variables

查看:28
本文介绍了wf4 一个活动只能访问自己的实现变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有变量(C# 表达式)的活动,但无法读取它们的值.

I have an activity with variables (which are C# expressions), but not able to read their values.

    public Collection<Variable> Variables { get; } = new Collection<Variable>();

    protected override void DoExecute(NativeActivityContext context)
    {
        var x = Variables.FirstOrDefault(...).Get(context);
    }

导致

Activity '1.1: MyActivity' cannot access this variable 
because it is declared at the scope of activity '1.1: MyActivity'.  
An activity can only access its own implementation variables.

我试图通过缓存元数据公开它们

I attempted to expose them via cachemetadata

    protected override void CacheMetadata(NativeActivityMetadata metadata)
    {
        metadata.SetImplementationVariablesCollection(Variables);
    }

结果是

Exception <System.NotSupportedException: 
Expression Activity type 'CSharpValue`1' requires compilation in order to run.  
Please ensure that the workflow has been compiled.

我的变量是 c# 表达式并用

My variables are c# expressions and compiled with

var wwfActivity = ActivityXamlServices.Load(xamlReader, new ActivityXamlServicesSettings {CompileExpressions = true});

推荐答案

我能够用

var var = context.DataContext.GetProperties()["variableName"];
var value = var.GetValue(context.DataContext) as Whatever;

没有覆盖CacheMetadata方法,但感觉有点奇怪;

without overriding the CacheMetadata method, but it feels a lil weird;

这篇关于wf4 一个活动只能访问自己的实现变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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