在设计器中为wf4

时间:2015-06-03 08:17:59

标签: c# workflow-foundation-4 workflow-foundation

我有一个扩展NativeActivity的类

我想允许从设计器向活动范围添加变量。如何修改我的活动代码,以便设计师让我添加变量?

No option to add variables in custom activity through designer

我的代码

public class MyActivity : NativeActivity<bool>
{
    public InArgument<string> SomeInArg { get; set; }

    public InArgument<object> RefInArg { get; set; }

    public WorkflowDataContext Data { get; set; }

    public Collection<Variable> Variables { get; set; }

    protected override void Execute(NativeActivityContext context)
    {
        Result.Set(context, true);
    }
}

感谢。

2 个答案:

答案 0 :(得分:0)

令人惊讶的是,添加一个返回空集合的getter - 解决了这个问题。我怀疑设计者试图以某种方式访问​​variables集合,当返回null时 - 它没有提供在设计器中设置变量的选项。

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

但是现在尝试访问变量会导致

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.

答案 1 :(得分:0)

尝试:

Collection<Variable> variables;
public Collection<Variable> Variables
    {
        get
        {
            if (this.variables == null)
            {
                this.variables = new Collection<Variable>();

            }
            return this.variables;
        }
    }

只有在避免访问&#34;访问&#34;问题。