locked
Switch in C# vs. WF RRS feed

  • Question

  • I am trying to translate this from C# to WF:

    switch (caseSwitch)
    {
        case "drunk":
        case "very drunk":
                 result = "don't drive";
                 break;
        default:
                 result = "drive";
                 break;
    }

    I am using System.Activities.Statements.Switch (no System.Activities.Statements.FlowSwitch).

    I am looking for the best way to reproduce the "fall" feature ('drunk' and 'very drunk' will execute the same code).

    Thank you in advance.


    jlcano

    Monday, August 18, 2014 4:14 PM

Answers

  • Please refer to the sample about switch in workflow:

    new Switch<int>()
    {
        DisplayName = "Verify Value from User",
        Expression = ExpressionServices.Convert<int>( env => numberFromUser.Get(env).CompareTo(numberToGuess.Get(env)) ),
        Cases = 
        {
            { 0, new Assign<bool>()
                {
                    To = new OutArgument<bool>(finished),
                    Value = true
                }
            },
            {  1, new WriteLine() { Text = "    Try a lower number number..." } }, 
            { -1, new WriteLine() { Text = "    Try a higher number" } }
        }
    }
    

    http://msdn.microsoft.com/en-gb/library/vstudio/dd647669(v=vs.100).aspx


    Tuesday, August 19, 2014 6:31 AM