• 大小: 24.76MB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2023-07-09
  • 语言: C#
  • 标签: Cefglue  c#互调JS  

资源简介

Xilium.Cefglue,c#与JS代码互调

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace TestJsCall
{
    public class CefjavascriptEx
    {
        /// 
        /// 利用反射,将对象的属性、方法映射成注册JS方法的脚本,
        /// object obj 需要被映射的对象,
        /// String jsName JS调用的对象名称,
        /// return String 返回注册JS的脚本
        /// 

        /// 需要被映射的对象
        /// JS调用的对象名称
        /// 返回注册JS的脚本
        public static String CreateJsCodeByobject(object obj String jsName)
        {
            String jsCode = “function “ + jsName + @“() {}
                if (!“ + jsName + “) “ + jsName + @“ = {};
                (function() {“;

            try
            {
                Type objType = obj.GetType();
                MethodInfo[] methods = objType.GetMethods();
                String pm = ““ fname = ““ func = ““;
                for (int i = 0 j = methods.Length; i < j; i++)
                {
                    pm = ““;
                    fname = methods[i].Name;
                    ParameterInfo[] param = methods[i].GetParameters();
                    for (int k = 0 x = param.Length; k < x; k++)
                    {
                        pm += “arg“ + k;
                        if (k < (x - 1))
                        {
                            pm += “ “;
                        }
                    } 
                    func = jsName + “.“ + fname + “ = function(“ + pm + @“) {
                        native function “ + fname + “(“ + pm + @“);
                        return “ + fname + “(“ + pm + @“);
                    };“;
                    
                    jsCode += func;
                }
               
            }catch(Exception e){
                System.Windows.Forms.MessageBox.Show(e.Message);
            }            

            jsCode += @“})();“;
            return jsCode;
        }
        
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-03-14 00:16  TestJsCall\
     目录           0  2015-03-14 00:55  TestJsCall\TestJsCall\
     文件         187  2015-03-14 00:16  TestJsCall\TestJsCall\App.config
     文件        2216  2015-03-14 00:55  TestJsCall\TestJsCall\CefjavascriptEx.cs
     文件        4341  2015-03-14 00:24  TestJsCall\TestJsCall\CefJsV8Handler.cs
     文件         630  2015-03-14 00:24  TestJsCall\TestJsCall\CefWebApp.cs
     文件         846  2015-03-14 00:54  TestJsCall\TestJsCall\DemoRenderProcessHandler.cs
     文件        5918  2015-03-14 00:51  TestJsCall\TestJsCall\Form1.Designer.cs
     文件        1534  2015-03-14 00:51  TestJsCall\TestJsCall\Form1.cs
     文件        6015  2015-03-14 00:51  TestJsCall\TestJsCall\Form1.resx
     文件        1195  2015-03-14 00:24  TestJsCall\TestJsCall\JsEvent.cs
     文件        2199  2015-03-14 00:52  TestJsCall\TestJsCall\Program.cs
     目录           0  2015-03-14 00:16  TestJsCall\TestJsCall\Properties\
     文件        1344  2015-03-14 00:16  TestJsCall\TestJsCall\Properties\AssemblyInfo.cs
     文件        2872  2015-03-14 00:16  TestJsCall\TestJsCall\Properties\Resources.Designer.cs
     文件        5612  2015-03-14 00:16  TestJsCall\TestJsCall\Properties\Resources.resx
     文件        1097  2015-03-14 00:16  TestJsCall\TestJsCall\Properties\Settings.Designer.cs
     文件         249  2015-03-14 00:16  TestJsCall\TestJsCall\Properties\Settings.settings
     文件        4673  2015-03-14 00:25  TestJsCall\TestJsCall\TestJsCall.csproj
     目录           0  2015-03-14 00:16  TestJsCall\TestJsCall\bin\
     目录           0  2015-03-14 00:27  TestJsCall\TestJsCall\bin\Debug\
     文件      114688  2012-08-27 17:26  TestJsCall\TestJsCall\bin\Debug\ICSharpCode.SharpZipLib.dll
     文件       15872  2015-03-14 00:51  TestJsCall\TestJsCall\bin\Debug\TestJsCall.exe
     文件         187  2015-03-14 00:16  TestJsCall\TestJsCall\bin\Debug\TestJsCall.exe.config
     文件       42496  2015-03-14 00:51  TestJsCall\TestJsCall\bin\Debug\TestJsCall.pdb
     文件       24224  2015-03-14 00:20  TestJsCall\TestJsCall\bin\Debug\TestJsCall.vshost.exe
     文件         187  2015-03-14 00:16  TestJsCall\TestJsCall\bin\Debug\TestJsCall.vshost.exe.config
     文件         490  2013-06-18 20:28  TestJsCall\TestJsCall\bin\Debug\TestJsCall.vshost.exe.manifest
     文件       23040  2015-03-12 23:37  TestJsCall\TestJsCall\bin\Debug\Xilium.CefGlue.Demo.dll
     文件       26624  2015-03-11 20:23  TestJsCall\TestJsCall\bin\Debug\Xilium.CefGlue.WindowsForms.dll
     文件      547328  2015-03-12 23:28  TestJsCall\TestJsCall\bin\Debug\Xilium.CefGlue.dll
............此处省略29个文件信息

评论

共有 条评论

相关资源