資源簡介
Xilium.Cefglue JS與C#相互調用Demo, 詳細注釋Xilium.Cefglue JS與C#相互調用Demo
代碼片段和文件信息
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?????????????????{
????????????????????pm?=?““;
????????????????????fname?=?methods[i].Name;
????????????????????ParameterInfo[]?param?=?methods[i].GetParameters();
????????????????????for?(int?k?=?0?x?=?param.Length;?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;
????????}
????????
????}
????///?
????///?另外一種組裝JS方法
????///?//第二種方法
????//??使用參考http://blog.csdn.net/nishiayan/article/details/77941471
????///?
????public?class?GeneratejavascriptFull
????{
????????string?_extensionName?=?string.Empty;
????????string?_functionName?=?string.Empty;
????????Dictionary?_methodName?=?new?Dictionary();
????????//
????????Dictionary?_getterPropertyName?=?new?Dictionary();
????????//?保存setter?名稱?和參數。?與?_setterPropertyArgs?成對出現。
????????Dictionary?_setterPropertyName?=?new?Dictionary();
????????Dictionary?_setterPropertyArgs?=?new?Dictionary();
????????//自定義javascript代碼
????????List?_customjavascript?=?new?List();
????????///?
????????///?
????????///?
????????///?
?????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-11-21?12:16??TestJsCall\
?????目錄???????????0??2017-11-21?12:16??TestJsCall\.vs\
?????目錄???????????0??2017-11-21?12:16??TestJsCall\.vs\TestJsCall\
?????目錄???????????0??2017-11-21?12:16??TestJsCall\.vs\TestJsCall\v14\
?????文件???????14848??2015-03-14?00:52??TestJsCall\.vs\TestJsCall\v14\.suo
?????目錄???????????0??2017-11-21?12:34??TestJsCall\TestJsCall\
?????文件?????????999??2015-03-14?00:16??TestJsCall\TestJsCall.sln
?????文件???????14848??2015-03-14?00:52??TestJsCall\TestJsCall.v12.suo
?????文件?????????187??2015-03-14?00:16??TestJsCall\TestJsCall\App.config
?????目錄???????????0??2015-03-14?00:16??TestJsCall\TestJsCall\bin\
?????目錄???????????0??2017-11-21?12:34??TestJsCall\TestJsCall\bin\Debug\
?????文件?????2626380??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\cef.pak
?????文件?????2106216??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\d3dcompiler_43.dll
?????文件?????3231696??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\d3dcompiler_46.dll
?????文件?????3222691??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\devtools_resources.pak
?????文件??????873472??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\ffmpegsumo.dll
?????文件??????114688??2012-08-27?17:26??TestJsCall\TestJsCall\bin\Debug\ICSharpCode.SharpZipLib.dll
?????文件?????9956864??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\icudt.dll
?????文件????????1179??2015-03-14?00:50??TestJsCall\TestJsCall\bin\Debug\index.html
?????文件????38703104??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\libcef.dll
?????文件??????102400??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\libEGL.dll
?????文件??????880128??2013-10-31?20:37??TestJsCall\TestJsCall\bin\Debug\libGLESv2.dll
?????目錄???????????0??2015-03-14?00:22??TestJsCall\TestJsCall\bin\Debug\locales\
?????文件????????6371??2013-10-31?19:24??TestJsCall\TestJsCall\bin\Debug\locales\en-US.pak
?????文件????????6407??2013-10-31?19:24??TestJsCall\TestJsCall\bin\Debug\locales\zh-CN.pak
?????文件???????18432??2017-11-21?12:34??TestJsCall\TestJsCall\bin\Debug\TestJsCall.exe
?????文件?????????187??2015-03-14?00:16??TestJsCall\TestJsCall\bin\Debug\TestJsCall.exe.config
?????文件???????42496??2017-11-21?12:34??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
............此處省略34個文件信息
- 上一篇:遙感圖像處理課程設計代碼
- 下一篇:C#高級編程(第11版_高清版_課程+源代碼)
評論
共有 條評論