2012-03-25 69 views
0

C#:IHTMLDocument InvokeMember返回的JavaScript如何轉換爲C#對象

public object InvokeScript(string ScriptName, object[] Data){ 
    ..... 
    return oScript.GetType().InvokeMember(ScriptName, 
    System.Reflection.BindingFlags.GetProperty, null, oScript, Data); 
} 

的javascript:

var myuser= [{a:3,b:4},{c:9,d:10}]; 

C#電話:

object result = web.InvokeScript("myuser"); 

如何訪問結果對象? 謝謝!

回答

0

我延伸使用

web_browser.ObjectForScripting =新共享對象的窗口瀏覽器對象();

回調PARAMS回報陣列

[PermissionSet(SecurityAction.Demand, Name = "FullTrust")] 
[System.Runtime.InteropServices.ComVisibleAttribute(true)] 
public class SharedObject 
{ 
    public void GetValue(string name, object callback) 
    { 
     // === some code === ... 
     SendCallback(callback, result); 
    } 

    protected void SendCallback(object callback, object value) 
    { 
     callback.GetType().InvokeMember(
      name: "[DispID=0]", 
      invokeAttr: BindingFlags.Instance | BindingFlags.InvokeMethod, 
      binder: null, 
      target: callback, 
      args: new Object[] { value }); 
    } 

} 
相關問題