Example #1
0
 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
     {
     }
 }
Example #2
0
        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);
        }