国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C# > 正文

C#執(zhí)行js動態(tài)編譯的方法

2019-10-29 21:43:21
字體:
供稿:網(wǎng)友
這篇文章主要介紹了C#執(zhí)行js動態(tài)編譯的方法,是涉及動態(tài)編譯腳本非常實用的技巧,需要的朋友可以參考下
 

本文實例講述了C#執(zhí)行js動態(tài)編譯的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

 

復(fù)制代碼代碼如下:
using System;  
using System.CodeDom.Compiler;  
using System.Collections.Generic;  
using System.Linq;  
using System.Reflection;  
using System.Text;  
using System.Threading.Tasks;  
  
namespace webpro  
{  
    public class JScripta  
    {  
        private static readonly CodeDomProvider _provider = new Microsoft.JScript.JScriptCodeProvider();  
        private static Type _evaluateType;  
        private const string scriptStr = @"package fhs  
            {  
                    public class MyJs  
                    {  
                      public static function test1(paramr1)  
                      {   
                            var retString  =   paramr1+ '是無敵的!';  
                            return retString;  
                      }  
    
                    }  
            }";  
        public static object JScriptRun(string jsMethodName,object[] testParams)  
        {  
            //編譯的參數(shù)  
            CompilerParameters parameters = new CompilerParameters();  
            parameters.GenerateInMemory = true;  
            CompilerResults results = _provider.CompileAssemblyFromSource(parameters, scriptStr);  
            Assembly assembly = results.CompiledAssembly;  
  
            //動態(tài)編譯腳本中的內(nèi)容  
            _evaluateType = assembly.GetType("fhs.MyJs");  
  
            //執(zhí)行指定的方法并傳參數(shù)  
            object retObj = _evaluateType.InvokeMember(jsMethodName, BindingFlags.InvokeMethod,  
                        null, null, testParams);  
            return retObj;  
        }  
    }  
}

 

希望本文所述對大家的C#程序設(shè)計有所幫助。


發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 铜川市| 五莲县| 安乡县| 两当县| 西畴县| 海原县| 临沧市| 察哈| 黄山市| 白河县| 莫力| 成安县| 东光县| 奇台县| 德江县| 香格里拉县| 镇原县| 信宜市| 石柱| 南和县| 广灵县| 江西省| 建水县| 吐鲁番市| 怀宁县| 平舆县| 广元市| 石河子市| 江华| 芒康县| 从化市| 安丘市| 缙云县| 博客| 威信县| 宜宾市| 梁河县| 南华县| 广西| 虎林市| 兴宁市|