1
votes

Lets say I create a simple workflow containing two variables, result of type Boolean and myInt of type Integer. Now add an activity "Assign", placing result in the result box, and Integer.TryParse("22", myInt) in the right hand expression. After running this activity, the variable still has the value 0.

Why is the result of the TryParse call not correctly stored in the variable? (No errors are generated here either)

2

2 Answers

2
votes

That's not how WF works. Variables don't have the concept of in/out as arguments. They don't implement implicit operators so the result will never be stored as you wish.

Either you implement your own TryParse activity or you can use InvokeMethod like this:

var resultVar = new Variable<bool>("result");
var myIntVar = new Variable<int>("myInt");

var activity = new Sequence
{
    Variables = 
    {
        resultVar,
        myIntVar
    },
    Activities =
    {
        new InvokeMethod
        {
            TargetType = typeof(int),
            MethodName = "TryParse",
            Result = new OutArgument<bool>(resultVar),
            Parameters = 
            {
                new InArgument<string>("22"),
                new OutArgument<int>(myIntVar)
            }
        },
        new WriteLine
        {
            Text = new VisualBasicValue<string>(@"""INT: "" & myInt")
        }
    }
};
1
votes

If you look under obj/x86/Debug or where ever your temp files are going in your project, you will find some intermediary .cs files that could satisfy your curiosity. I tried this out, and you get a class with a private int myInt and private bool result and a tryparse statement using those variables. Hence no blow up, though I did see some issues in my output window!