本文共 850 字,大约阅读时间需要 2 分钟。
宿主环境内有这样一个数据,如下:
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()的属性信息了。
本文转自生鱼片博客园博客,原文链接:,如需转载请自行联系原作者