我有一个C#程序集,它有方法和getter / setter。我可以在vb6的comvisible C#程序集中调用该方法,但getter / setter失败并出现错误 - “Object不支持此属性或方法”
例如,我在.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中运行良好。但是,如果我使用一个返回另一个对象的属性,它就会失败。