Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Answered Change concrete type of generic activity

  • Monday, October 05, 2009 2:46 PM
     
      Has Code
    I've created my own generic activity:

    public class MyActivity<T> : CodeActivity { ... }
    When I add an instance of this activity to a sequence I get the dialog "Select concrete type(s) for generic definition". Is it possible to change the generic type of a existing activity? In the xaml i see the x:TypeArguments attribute so it's possible to change it in the xaml. Is this also possible using the property grid?

All Replies

  • Monday, October 05, 2009 10:16 PM
     
     Answered
    Right now in Beta 1, I don't think there is a way to do this through the designer.  The only way I've done it is to delete the activity and re-add it.  Hopefully there are many improvements to the designer in Beta 2.
    • Marked As Answer by Dutchdre Tuesday, October 06, 2009 6:38 AM
    •  
  • Tuesday, October 06, 2009 4:10 AM
     
     Answered
    Hi,

    In Beta 1, you need to delete the activity and add it again. This is the only option.  If a designer contains some custom activity and you change that custom activity, the designer becomes invalid. So we need to delete the Custom activity and add it freshly and again set its properties. Hope this issue gets resolved in Beta2.
    • Proposed As Answer by Sneha Gupta Tuesday, October 06, 2009 4:10 AM
    • Marked As Answer by Dutchdre Tuesday, October 06, 2009 6:38 AM
    •  
  • Tuesday, October 06, 2009 7:36 AM
     
     
    Thanks for your answers. Hopefully Beta 2 will fix it.
  • Wednesday, October 07, 2009 8:56 PM
     
     
    The short answer is that this will not be fixed in beta2.

    The longer answer is that there isn't a good way to fix this in the general case.  If you use TResult elsewhere, for instance to have a property of that type, there does not exist a safe "general" transform from T_old to T_new.  We've investigated and prototyped a way that an activity could opt in to provide special behavior on the type change to specify how to handle it, but that will not be a publicly extensible thing that can be used in VS2010. 

    We've special cased some of our generic activity designers (like ForEach<T> ) so that you can do this switch.  You could build a custom designer that would surface the way to do a switch as well.

    Let me know what you think,

    Thanks,

    matt
    Program Manager -- wf designer -- http://blogs.msdn.com/mwinkle
  • Thursday, October 08, 2009 6:36 AM
     
     
    Unfortunately beta 2 won't solve this “problem”. Our process managers will manage our workflows and we are planning to develop our own designer. If there is a need to achieve this will try to implement our own refactoring method for this “problem”.

    Our end-user, the process managers, aren’t stereotype programmers and will ask us how to achieve this. I've asked this to the “community”, so I could get a clear explanation why this isn’t won’t work in a generic matter.

    Thanks for your explanation,

    Dutchdre
  • Thursday, October 08, 2009 7:12 AM
    Moderator
     
     
    If I remember correctly, there are some APIs that could allow you to add a custom context menu item 'Change Item Type', and implement change item type to 'morph' the item, replacing it with a new item. I might be able to post some more details later if this sounds interesting.
  • Thursday, October 08, 2009 5:56 PM
     
     
    Hi tilovell,

    This sounds very interesting. Could you please give me more details about this APIs?
  • Monday, October 19, 2009 5:30 PM
    Moderator
     
     
    I realized after posting it's still not possible in Beta1, but Beta2 is now announced, and here is some information. There are two parts to the workaround I suggest, the first is customizing the context menu, the second one is transmuting the object to have a different type. The first part I'm going to gloss over because I'm still not very expert on WPF and the first way I think of might be a really bad way.

    The second part: All the objects in the model tree actually exist as real objects, and it isn't possible to directly turn a List<int> into a List<string> for instance, but it is possible to remove all references to the List<int> in the Model Tree and replace all references to it with references to a List<string>instead.

    The class designed to be useful for this in System.Activities.Presentation (was System.Activities.Design) is called MorphHelper. It has two main methods, MorphObject is the one you use to replace one object with another updating all references in the tree.

    Once you have done this, you still have one problem - data loss. All the properties on the old object have not yet been copied over to the new object. The second main method of MorphHelper is MorphProperties, which attempts to copy over as many properties as possible - although not all properties can be copied automatically.

    MorphHelper:
    http://msdn.microsoft.com/en-us/library/system.activities.presentation.model.morphhelper(VS.100).aspx