问题
I have a workflow composed of many custom activities. All these activities need to access startup arguments of the workflow itself. I can define InArgument inside all these custom activities and bind the workflow arguments to custom activity arguments but I am not comfortable with this solution. What is the best way to access workflow level argument and variable declarations from custom activities. Can I get them from ActivityContext?
Thanks.
回答1:
One way we've looked at this with our custom activities is using the Properties property available in the ActivityContext. We have an activity with an InArgument which adds an ExecutionProperty in the execute method, so you end up with:
public InArgument<Custom> MyObject {get;set;}
...
context.Properties.Add("Contact",MyObject.Get(context));
Then in your other activities you can check to see if this has been set
context.Properties.Find("Contact")
Obviously if you're doing this a lot I'd recommend using a constant somewhere rather than magic strings, but it should save you having to add the same argument over and over when designing.
来源:https://stackoverflow.com/questions/2857388/accessing-arguments-workflow-variables-from-custom-activities