欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2015年01月20日 09:20:00   投稿:shichen2014  
這篇文章主要介紹了C#執(zhí)行js動(dòng)態(tài)編譯的方法,是涉及動(dòng)態(tài)編譯腳本非常實(shí)用的技巧,需要的朋友可以參考下

本文實(shí)例講述了C#執(zhí)行js動(dòng)態(tài)編譯的方法。分享給大家供大家參考。具體實(shí)現(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; 
 
            //動(dòng)態(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è)計(jì)有所幫助。

相關(guān)文章

最新評論