博客园  :: 首页  :: 联系 :: 订阅 订阅  :: 管理

使用SymbolResolver在Activity内访问宿主环境信息

Posted on 2011-03-11 10:42  生鱼片  阅读(1648)  评论(0编辑  收藏  举报

宿主环境内有这样一个数据,如下:

public class MyObject
    {
        public int MyValue { get; set; }
        public string MyString { get; set; }
    }

 

在Activity内访问该对象实例的方法如下:

public sealed class SymbolUser : CodeActivity
    {
        protected override void Execute(CodeActivityContext context)
        {
            SymbolResolver symbolResolver = context.GetExtension<SymbolResolver>();
            MyObject obj = symbolResolver["CustomObject"] as MyObject;
            Console.WriteLine(obj.MyString);
        }

    }

 

宿主的代码如下:

class Program
    {
        static void Main(string[] args)
        {
            WorkflowApplication WFApp = new WorkflowApplication(new Workflow1());
            SymbolResolver symbolResolver = new SymbolResolver();
            WFApp.Extensions.Add(symbolResolver);
            symbolResolver.Add("CustomObject", new MyObject() { MyValue = 1, MyString = "TestString" });
            WFApp.Run();
            Console.ReadLine();

        }
    }

当SymbolUser Activity执行的时候就可以得到new MyObject()的属性信息了。