我有一个 C# 程序集,它有方法和 getter/setter。我可以从 vb6 调用可组合 C# 程序集中的方法,但是 getter/setter 失败并出现错误 - '对象不支持此属性或方法'
例如,我在 .net 程序集中的类是这样的:
public class Test{
SubMain _subMain;
public Test()
{
_subMain = new SubMain();
}
public string Dump(){ return "test"; }
public SubMain SubMain
{
get
{
return _subMain;
}
}
public class SubMain
{
public SubMain()
{
}
public string Dump()
{
return "SubMain";
}
}
----
vbscript:
Set obj = CreateObject("SampleCSForCOM.Main")
str = obj.Dump()
wscript.echo "method string="+str
wscript.echo "property string="+obj.SubMain.Dump()
----
Error in vbscript:
C:\test>cscript test.vbs
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.
method string=Main
C:\test\test.vbs(4, 1) Microsoft VBScript runtime error: Object doesn't support
this property or method: 'obj.SubMain'
问题:如果我使用返回字符串的属性,它在 vbscript 中运行良好。但是,如果我使用返回另一个对象的属性,它就会失败。