c#运行JS代码
来源:互联网 发布:oncity中山网络社区 编辑:程序博客网 时间:2024/05/17 07:29
Jint,
Gitbub网址:https://github.com/sebastienros/jint
编译好的dll文件:https://pan.baidu.com/s/1qYhSM64
使用方法示例:
class Program{ static Jint.Engine _engine; public static void Print(object s) { if (s == null) s = "null"; Console.WriteLine(s.ToString()); } private static Jint.Engine CreateEngine() { return new Engine().SetValue("print", new Action<object>(Print)); } static void Main(string[] args) { var source = @" var s = 'Hello World From JavaScript '; for(var i=0; i<4; i++) { print(s + i); } s; // Evaluate and return the expression "; var s = CreateEngine().Execute(source).GetCompletionValue(); Console.WriteLine(s.AsString()); Console.ReadLine(); }}
更多教程,访问:http://frederictorres.blogspot.jp/2014/04/jint-tutorials.html
注意,Jint默认不支持escape和unescape函数,如果代码中有用到这两个函数,需要自己自定义一下。
var escape = function (s) { s = s.toString(s); var n = s.length; var result = ""; for(var k = 0; k < n; k++) { var c = s[k]; var S = ""; var code = c.charCodeAt(0); if(("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./").indexOf(c) > -1) { S = c; } else if(code < 256) { S = '%' + code.toString(16); } else { S = code.toString(16); S = "%u" + ("0000").substring(0, 4 - S.length) + S; } result = result + S; } return result;}; var unescape = function (s) { s = s.toString(s); var n = s.length; var result = ""; for(var k = 0; k < n; k++) { var c = s[k]; if(c == '%') { if(k <= (n - 6)) { if(s[k + 1] == 'u') { if(("0123456789abcdef").indexOf(s[k + 2]) > -1 && ("0123456789abcdef").indexOf(s[k + 3]) > -1 && ("0123456789abcdef").indexOf(s[k + 4]) > -1 && ("0123456789abcdef").indexOf(s[k + 5]) > -1) { c = String.fromCharCode(parseInt(s.substring(k + 2, k + 7), 16)); k = k + 5; } else { if(k <= (n - 3) && ("0123456789abcdef").indexOf(s[k + 1]) > -1 && ("0123456789abcdef").indexOf(s[k + 2]) > -1) { c = String.fromCharCode(parseInt(("00" + s.substring(k + 1, k + 3)), 16)); k = k + 2; } } } else { if(k <= (n - 3) && ("0123456789abcdef").indexOf(s[k + 1]) > -1 && ("0123456789abcdef").indexOf(s[k + 2]) > -1) { c = String.fromCharCode(parseInt(("00" + s.substring(k + 1, k + 3)), 16)); k = k + 2; } } } else if(("0123456789abcdef").indexOf(s[k + 1]) > -1 && ("0123456789abcdef").indexOf(s[k + 2]) > -1) { c = String.fromCharCode(parseInt(("00" + s.substring(k + 1, k + 3)), 16)); k = k + 2; } } result = result + c; } return result;};
阅读全文
0 0
- c#运行JS代码
- 网页运行js代码
- js代码不运行
- python 运行js代码
- JS:运行代码的代码
- C#代码试运行在服务器端----JS代码是运行在浏览器端
- js代码执行C#代码
- C# 代码运行时间统计
- C# 统计代码运行时间
- 计算C#代码运行时间
- c#检查代码运行时间
- js 复制,保存,运行代码
- js javascript runcode 运行代码
- 网页中运行JS代码
- 可以即时运行JS的JS代码
- JS在指定时间运行代码(可运行后台代码)
- JS执行C#后台代码
- 在线JS转C#代码
- matlab的取整函数
- POJ2566-Bound Found
- python学习一
- vmware安装报错: This product may not be installed on a computer that has Microsoft HyperV installed.
- TS流分析
- c#运行JS代码
- JAVA动态代理
- 重写eqlus与hashCode方法例子
- 解决Qt5.8加载qt_zh_CN.qm之后QMessageBox仍显示英文的问题
- C-ordered contiguous
- IntelliJ IDEA 开发Web应用图文教程
- Vue CheckBox 全选
- 将EXCEL导到oracle数据库
- RabbitMQ (五)主题(Topic)