locked
Using reflection to obtain inargument values for activity RRS feed

  • Question

  • Hello everyone,

         Is it possible to use reflection inside a custom activity to get any values needed from its parent activity instead of using inarguments?  For instance, is it possible within a custom activity to get a reference to its parent activity and then get the current values of specific variables in that parents Variable collection (assuming one exists)?  If so, then I really have three specific parts to my question: 
    1.  How to get at the Variables collection of a parent activity through reflection from within a custom activity.
    2.  How to get the current value of a specific variable in the collection obtained in part 1, and set a property in my custom activity to this value.
    3.  How to set the value of a variable (in the collection from part 1 using reflection) to the result of some computation in my custom activity, making this value the new current value for this variable that subsequently executed activities would see.

    Basically, I am asking how to get and set variables from within my custom activity without the need for in and out arguments.  Also, I am well aware of the performance implications of using reflection in general.

    Thanks in advance,

    Bob

    Note:  I probably don't need to see specific code in the answers, if I do I can just follow-up with questions on specific items.  I understand reflection fairly well, so mostly I need just a high level description of how you might go about this.
    Friday, December 4, 2009 4:17 PM

Answers

  • Bob,

    Check out Nate's response to a similar question here.

    matt
    Program Manager -- wf designer -- http://blogs.msdn.com/mwinkle
    Friday, December 4, 2009 9:47 PM
  • Let me quote the really important part from Nate's response for anyone who lands on this thread in the future:


    By the way, this [poking around the DataContext] is NOT recommended as you are bypassing the data model.  This means that future enhancements (such as static data dependency analysis) will not be able to understand the dependencies that your activity has.

    See the samples regarding arguments (the way to get values into and out of an activity) and ActivityDelegate/Action/Func (the way for a parent to provide values to and expect values from a child) for the correct way to do this.

    The data context is provided for interoperability with other application models (such as WPF) and not for bypassing the data model within a workflow.

    Program Manager -- wf designer -- http://blogs.msdn.com/mwinkle
    Friday, December 4, 2009 10:30 PM

All replies

  • Bob,

    Check out Nate's response to a similar question here.

    matt
    Program Manager -- wf designer -- http://blogs.msdn.com/mwinkle
    Friday, December 4, 2009 9:47 PM
  • Matt,

         That looks like the direction I need to go.  Thanks for pointing me in the right direction!

    bob
    Friday, December 4, 2009 9:59 PM
  • Let me quote the really important part from Nate's response for anyone who lands on this thread in the future:


    By the way, this [poking around the DataContext] is NOT recommended as you are bypassing the data model.  This means that future enhancements (such as static data dependency analysis) will not be able to understand the dependencies that your activity has.

    See the samples regarding arguments (the way to get values into and out of an activity) and ActivityDelegate/Action/Func (the way for a parent to provide values to and expect values from a child) for the correct way to do this.

    The data context is provided for interoperability with other application models (such as WPF) and not for bypassing the data model within a workflow.

    Program Manager -- wf designer -- http://blogs.msdn.com/mwinkle
    Friday, December 4, 2009 10:30 PM
  • Matt,

         What can I say?  I like to live dangerously :)

    bob
    Friday, December 4, 2009 11:05 PM