private long OnMethodCall(IntPtr es, long obj, IntPtr args, int argCount) { var paramters = _methodInfo.GetParameters(); if (argCount < paramters.Length) { return(MBApi.jsUndefined()); } object[] param = new object[argCount]; for (int i = 0; i < param.Length; i++) { var paramInfo = paramters[i]; var pType = paramInfo.ParameterType; var tType = paramInfo.ParameterType.GetElementType(); if (tType != null) { pType = tType; } long t = MBApi.jsArg(es, i); param[i] = JsConvert. ConvertJSToObject(es, t, pType); } var res = _methodInfo.Invoke(_obj, param); return(JsConvert.ConvertObjectToJS(es, res)); }
private long OnCreateObject(IntPtr es, long obj, IntPtr args, int argCount) { try { var typeName_Val = MBApi.jsArg(es, 0); if (!MBApi.jsIsString(typeName_Val)) { return(MBApi.jsUndefined()); } string typeName = ExtApi.GetJsString(es, typeName_Val); Type localType = null; foreach (var ass in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var type in ass.GetTypes()) { if (type.FullName == typeName) { localType = type; break; } } } if (localType == null) { return(MBApi.jsUndefined()); } object[] obj_args = new object[argCount - 1]; for (int i = 1; i < obj_args.Length; i++) { obj_args[i] = JsConvert.ConvertJSToObject(es, MBApi.jsArg(es, i), typeof(object)); } var localObj = Activator.CreateInstance(localType, obj_args); var webView = MBApi.jsGetWebView(es); CSharpObject local_obj = new CSharpObject(webView, localObj); lock (sharpObjects) { List <CSharpObject> list = null; if (!sharpObjects.ContainsKey(webView)) { list = new List <CSharpObject>(); } else { list = sharpObjects[webView]; } list.Add(local_obj); } return(local_obj.ScriptValue); } finally { } }
private long OnCreateComObj(IntPtr es, long obj, IntPtr args, int argCount) { var typeName_ID = MBApi.jsArg(es, 0); if (!MBApi.jsIsString(typeName_ID)) { return(MBApi.jsUndefined()); } string typeID = ExtApi.GetJsString(es, typeName_ID); Guid clsId = new Guid(typeID); Type localType = Type.GetTypeFromCLSID(clsId); if (localType == null) { return(MBApi.jsUndefined()); } object[] obj_args = new object[argCount - 1]; for (int i = 1; i < obj_args.Length; i++) { obj_args[i] = JsConvert.ConvertJSToObject(es, MBApi.jsArg(es, i), typeof(object)); } var localObj = Activator.CreateInstance(localType, obj_args); var webView = MBApi.jsGetWebView(es); CSharpObject local_obj = new CSharpObject(webView, localObj); lock (sharpObjects) { List <CSharpObject> list = null; if (!sharpObjects.ContainsKey(webView)) { list = new List <CSharpObject>(); } else { list = sharpObjects[webView]; } list.Add(local_obj); } return(local_obj.ScriptValue); }