locked
How to implement a non generic assign type check RRS feed

  • Question

  • Hi All,

     

    I'm trying to implement an assign activity, thing is that I don't wanna pop this generic type popup (the one you choose type in), same as microsoft does,

     

    To do so I added the Arguments without types as such:

     

     public InArgument From { get; set; }
     public OutArgument To { get; set; }
    

     

    The problem when I want to add a validation error if the type does not match (like if you assign object to int),

     

    To do so I added the following in CacheMetadata:

    protected override void CacheMetadata(CodeActivityMetadata metadata)
            {
    
                if (this.To != null && this.From != null)
                {
                    if (!this.To.ArgumentType.IsAssignableFrom(this.From.ArgumentType))
                    {
                        metadata.AddValidationError(this.DisplayName + " cannot convert " + this.From.ArgumentType.ToString() + " to " + this.To.ArgumentType.ToString());
                    }
                }
    
                base.CacheMetadata(metadata);   
            }
    


    When I place my assign in a flowchart and define variables (from the bottomvariable tab), validation works ok the first time, but if I change the type of the variable the CacheMetadata (though called) do not detect the type change, only removing and readding the variable works.

     

    Is there any way to detect the change made to variable type?

     

    Thanks in advance,

    Eyal.

     

    • Moved by Min Zhu Tuesday, December 13, 2011 6:21 AM (From:Windows Presentation Foundation (WPF))
    Sunday, December 11, 2011 11:48 AM

Answers

  • Hi Eyal,
    I guess you are working on a rehosted designer app?

    There's already a non generic Assign activity as part of the framework that does validation such as you are looking for, without any popup dialog.

    Just make sure you are adding Assign to your toolbox, and not Assign<,> or Assign`1 (depending on how you are adding it).

    (By the way, it also turns out that ArgumentType.IsAssignableFrom is probably not the best way to test this because, IsAssignableFrom doesn't allow implicit casts, type widening, etc.)

    Tim

    • Marked as answer by LeoTang Sunday, December 18, 2011 2:05 PM
    Wednesday, December 14, 2011 12:08 AM

All replies

  • Hi Eyal,

    I have moved your thread to Work Flow forum for better support.

    Best regards,


    Min Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Tuesday, December 13, 2011 6:20 AM
  • Hi Eyal,
    I guess you are working on a rehosted designer app?

    There's already a non generic Assign activity as part of the framework that does validation such as you are looking for, without any popup dialog.

    Just make sure you are adding Assign to your toolbox, and not Assign<,> or Assign`1 (depending on how you are adding it).

    (By the way, it also turns out that ArgumentType.IsAssignableFrom is probably not the best way to test this because, IsAssignableFrom doesn't allow implicit casts, type widening, etc.)

    Tim

    • Marked as answer by LeoTang Sunday, December 18, 2011 2:05 PM
    Wednesday, December 14, 2011 12:08 AM