Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I made a couple of changes to make your code work. </p> <ol> <li>The Variable constructor is changed to use the ActivityFunc overload </li> <li>The second WriteLine needs to call ToString() explicitly in the expression</li> </ol> <p>The corrected code is as follows </p> <pre><code>private static void Main(string[] args) { var testClass = new Test { MyString = "some string", MyBool = true }; var wf = new Sequence { Variables = { // Changed to use ActivityFunc so testClass is not interpreted as a literal new Variable&lt;Test&gt;("varName", ctx =&gt; testClass), }, Activities = { new WriteLine { Text = new VisualBasicValue&lt;string&gt;( "\"Test Class Properties: \" &amp; varName.MyString &amp; \"-\" &amp; varName.MyBool") }, // Changed to call ToString explicitly new WriteLine { Text = new VisualBasicValue&lt;string&gt;("\"Test Class ToString(): \" &amp; varName.ToString()") } } }; var settings = new VisualBasicSettings(); settings.ImportReferences.Add( new VisualBasicImportReference { Assembly = typeof(Test).Assembly.GetName().Name, Import = typeof(Test).Namespace }); // construct workflow VisualBasic.SetSettings(wf, settings); WorkflowInvoker.Invoke(wf); Console.ReadKey(); } </code></pre> <p>One more thing. Some have questioned why it was necessary to call Test.ToString() explicitly with the VB Concat operator. This is a curious issue and it is one of the places where a type declared in C# differs from a type declared in VB.</p> <p>C# uses the + operator for both addition and concatenation where VB has the &amp; operator for concat and a specific IL instruction op_Concat.</p> <p>If you declare your type in VB, you can overload the &amp; operator to eliminate the need to call ToString() in your expression.</p> <p>For example</p> <pre><code>Public Class Test Public Property MyString As String Public Property MyBool As Boolean Public Overrides Function ToString() As String Return "Test Class : " &amp; MyString + " - " &amp; MyBool End Function Public Shared Operator &amp;(ByVal left As String, ByVal right As Test) As String Return left &amp; "-" &amp; right.ToString End Operator End Class </code></pre> <p>When working on problems like in VB I often just create VB console apps to test things out apart from Workflow</p> <pre><code>Module Module1 Dim varName As New Test With {.MyBool = True, .MyString = "some string"} Sub Main() Console.WriteLine("Test Class Properties: " &amp; varName.MyString &amp; "-" &amp; varName.MyBool) Console.WriteLine("Test Class ToString(): " &amp; varName) Console.ReadKey() End Sub End Module </code></pre> <p>The IL emitted for this app shows the operator </p> <pre><code>IL_002f: ldstr "Test Class ToString(): " IL_0034: ldsfld class VBTest.Test VBTest.Module1::varName IL_0039: call string VBTest.Test::op_Concatenate(string, class VBTest.Test) IL_003e: call void [mscorlib]System.Console::WriteLine(string) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload