国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 青冈县| 略阳县| 灌阳县| 大足县| 清苑县| 抚州市| 东兴市| 廊坊市| 中卫市| 天台县| 黄梅县| 蕉岭县| 五华县| 阿拉善左旗| 杭锦后旗| 土默特左旗| 宁蒗| 乌拉特中旗| 科尔| 牟定县| 山丹县| 内乡县| 津南区| 五指山市| 海盐县| 东兰县| 巴里| 连南| 红桥区| 西盟| 永胜县| 廊坊市| 泽州县| 闸北区| 伊春市| 吉隆县| 城固县| 涞源县| 沁源县| 兴隆县| 通辽市|