蜗牛,在赛跑

--努力去改变吧
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

将js文件编译成动态链接库(dll)文件-2

Posted on 2007-07-16 14:00  body  阅读(256)  评论(0)    收藏  举报

此方法与上一方法相比,只是将jscript封装到dll中,运行后即可见到脚本代码,并不起到保护jscript的作用.

//添加引用
private void EmbedScriptCode()
{
 
// Add the script to declare the function
 string js = ReadResourceString("wf.ContextMenu.ContextMenu.js");

  
if (!Page.ClientScript.IsStartupScriptRegistered("ContextMenuHelper"))
  Page.ClientScript.RegisterStartupScript(
this.GetType(),"ContextMenuHelper", js);
}


private string ReadResourceString(string resourceName)
{
 Assembly dll 
= Assembly.GetExecutingAssembly();
 StreamReader reader;
 reader 
= new StreamReader(dll.GetManifestResourceStream(resourceName));
 
string js = reader.ReadToEnd();
 reader.Close();

 
return js;
}