宿主环境内有这样一个数据,如下:
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();
}
}