views:

89

answers:

2

I have a Workflow 4 activity that can be run on any number of classes that inherit from my base class. So, the activity is, naturally, generic. Similar to the ForEach or AddToCollection activities, my activity requires a type parameter.

My question is: can I create this activity in the designer with XAML? Keep in mind this is a composite activity, so the designer seems to be the best choice.

If I were to create it in code, it would look like this:

public class MyGenericActivity<T> : Activity where T : MyBaseClass
{
   //args would go here
   public MyGenericActivity()
   {
      this.Implementation = () => new Sequence
      {
         Activities = { //... }
      };
   }
}

While this solution would work, maintenance would most certainly be painful and you don't get any of the "niceties" of the designer, this way.

A: 

Not sure if you can but I suspect not. But even if you could why would you? A xaml activity is only markup and composition, there is no code, so how would you use the generic type.

The design time experience for someone using your activity is unrelated to how you create your activity. Just add a designer and give the user whatever design time experience you like. You can let them add multiple child activities using the WorkflowItemsPresenter.

Maurice
I'm not finding any evidence that I can do this either.As far as your question, "...how would you use the generic type" I would pass that type into the other activities within it. You see, we have a lot of activities already written (mostly CodeActivity) that take a type parameter. It would be nice if I didn't have to specify the type in my xaml, but could re-use the same xaml for all of my types.That way, my workflow host could decide which type to use and I wouldn't have to re-design the same xaml for every type. Also, the issue at hand is not the design-time experience. It is code re-use.
Jason Williams
Makes sense but I am afraid I don't know of any way to do this.
Maurice
+1  A: 

The XAML stack might possibly support it (not sure), but in VS 10 the workflow designer definitely does not let you do this.

Tim Lovell-Smith