WF4 – How to Cast in VB Expressions

If you are a C# developer using Workflow you might not know how VB does type conversion.

Imagine this simple example.  I’ve got some classes which use inheritance

    1: public abstract class Shape
    2: {
    3:     public int Top { get; set; }
    4:  
    5:     public int Left { get; set; }
    6: }
    7:  
    8: public class Circle : Shape
    9: {
   10:     public int Radius { get; set; }
   11: }
   12:  
   13: public class Square : Shape
   14: {
   15:     public int Length { get; set; }
   16:  
   17:     public int Width { get; set; }
   18: }

Then, in my workflow I create some variables

image

Watch what happens if I try to cast this using C# syntax

image

There are many options for type conversion in VB

The simplest thing is to just change this expression to use DirectCast.

SNAGHTML4c86f3f

Happy Coding!

Ron Jacobs

https://blogs.msdn.com/rjacobs

Twitter: @ronljacobs https://twitter.com/ronljacobs