开发者

Reading JScript (associative) array from .NET ActiveX component

I'm implementing an ActiveX component in C# (.NET 4.0) and I'm having trouble accessing JScript arrays; in this case an associative array. From a HTML page, I'm calling my component like this:

MyComponent.MyMethod({ "foo": "bar" });

My ActiveX component has the following method signature:

public void MyMethod(dynamic someArray)
{
    // someArray will be a RCW (__ComObject)
}

I figured I would be able to call all the usual stuff on this object through IDispatch. However, none of the properties and methods that are available on JavaScript arrays are accessible.

I've used parts of this Blog article to try and inspect what type of COM object I'm actually getting, but the DumpTypeInfo method shown there just gives me JScriptTypeInfo, which has no functions defined on it.

Plenty of articles discuss how to get arrays from .NET to JavaScript, but the other way around seems less than trivial as well. Any ideas?

PS: I've tried a bunch o开发者_运维知识库f other options, but mentioning them all probably won't help at this point.


I wonder if you solved this problem. I've tried something myself with WebBrowser control and ObjectForScripting property assigned to instance of the following class

[ComVisible(true)]
public class ObjectForScripting {
    public void Call(dynamic o) {
        Type t = o.GetType();
        var result = t.InvokeMember("a", System.Reflection.BindingFlags.GetProperty, null, o, null);
    }
}

Document executes window.external.Call({a:'b'}) and everything seems working fine, result gets value "b".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜