简体   繁体   中英

MSScriptControl.ScriptControlClass - access a sub-object of the main object

I want do add a huge object with lots of sub-objects to a ScriptControlClass. While accessing these sub-classes I get an error that the object is null or no object

MSScriptControl.ScriptControlClass js = new MSScriptControl.ScriptControlClass();
js.AllowUI = false;
js.Language = "JScript";
js.Reset();
js.AddObject("MyObject", myObject, false);

[ComVisible(true)]
class AAA
{
    public BBB Bbb { get; set; } 
}

class BBB
{
    public CCC Ccc { get; set; }
}

class CCC
{
    public string MyString { get; set; }
}

If I want to get the last string of my objects via this JScript-Code I get the error

var x = MyObject.Bbb.Ccc.MyString;

How can I do this?

I have to add to every class the ComVisible(true) attribute and not only to the first AAA Class

[ComVisible(true)]
public class AAA
{
    public BBB Bbb { get; set; }
}

[ComVisible(true)]
public class BBB
{
    public CCC Ccc { get; set; }
}

[ComVisible(true)]
public class CCC
{
    public string MyString { get; set; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM