c#使用脚本语言

use js script in c#

添加引用-com-Microsoft Script Control 1.0

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MSScriptControl;//重要
namespace baseTransfrom
{
    class Program
    {
        static string ExecuteScript(string sExpression, string sCode)//后一个参数是写脚本里的函数,一般为空。
        {
            MSScriptControl.ScriptControl scriptControl = new MSScriptControl.ScriptControl();
            scriptControl.UseSafeSubset = true;
            scriptControl.Language = "JScript";
            scriptControl.AddCode(sCode);
            try
            {
                string str = scriptControl.Eval(sExpression).ToString();
                return str;
            }
            catch (Exception ex)
            {
                string str = ex.Message;
            }
            return null;
        }
    }
}
posted @ 2017-04-05 19:58  xsthunder  阅读(1073)  评论(0)    收藏  举报