想我也一個自定義類(任何類),其方法和屬性:VisualBasicValue <T>:訪問自定義類及其方法性能
public class Test
{
public string MyString { get; set; }
public bool MyBool { get; set; }
public override string ToString()
{
return "Test Class : " + this.MyString + " - " + MyBool;
}
}
現在我想移動和處理其WF4之間的性能活動使用VisualBasicValue<T>
。例如:
public class Program
{
static void Main(string[] args)
{
Test testClass = new Test()
{
MyString = "some string",
MyBool = true
};
Sequence wf = new Sequence()
{
Variables =
{
new Variable<Test>("varName", testClass),
},
Activities =
{
new WriteLine() { Text = new VisualBasicValue<string>("\"Test Class Properties: \" & varName.MyString & \"-\" & varName.MyBool") },
new WriteLine() { Text = new VisualBasicValue<string>("\"Test Class ToString(): \" & varName") }
}
};
WorkflowInvoker.Invoke(wf);
Console.ReadKey();
}
}
此代碼編譯沒有問題。變量可以處理任何種類的類,但在運行時似乎會抱怨自定義類的用法。有些例外,如:
The following errors were encountered while processing the workflow tree:
'Literal<Test>': Literal only supports value types and the immutable type System.String. The type WorkflowConsoleApplication3.Test cannot be used as a literal.
'VisualBasicValue<String>': Compiler error(s) encountered processing expression ""Test Class ToString(): " & varName".
操作「&」不是類型「字符串」和「WorkflowConsoleApplication3.Test」定義。
我讀過,你可以沿着這條線做一些事情:
VisualBasicSettings vbSettings = new VisualBasicSettings();
vbSettings.ImportReferences.Add(new VisualBasicImportReference()
{
Assembly = typeof(Test).Assembly.GetName().Name,
Import = typeof(Test).Namespace
});
// construct workflow
VisualBasic.SetSettings(wf, vbSettings);
WorkflowInvoker.Invoke(wf);
但是,這並不似乎這樣的伎倆。任何幫助?
PS:在同一主題,有人可以給我一個小示例如何\在哪裏使用VisualBasicReference<T>' with
OutArgument`?我似乎可以在稍後階段使用它,但我可以找到任何示例。
是的!這正是問題所在。謝謝。 – Joao 2011-04-28 18:51:34