C # compilation Js-evaluator

Source: Internet
Author: User

forget where you turned around, mark.

//// <summary>///Dynamic Evaluation/// </summary> Public classevaluator{/// <summary>///evaluates, throws an exception if an expression is faulted/// </summary>/// <param name= "statement" >expressions, such as "1+2+3+4"</param>/// <returns>Results</returns> Public Static ObjectEval (stringstatement) {return_evaluatortype.invokemember ("Eval", BindingFlags.InvokeMethod,NULL, _evaluator,New Object[] {statement});}StaticEvaluator () {//constructing the compiled driver code for JScriptCodeDomProvider Provider = Codedomprovider.createprovider ("JScript"); CompilerParameters parameters;parameters=Newcompilerparameters ();p arameters. GenerateInMemory=true; CompilerResults Results;results=provider.compileassemblyfromsource (parameters, _jscriptsource); Assembly Assembly=Results.compiledassembly;_evaluatortype= assembly. GetType ("Evaluator"); _evaluator=Activator.CreateInstance (_evaluatortype);}Private Static Object_evaluator =NULL;Private StaticType _evaluatortype =NULL;//// <summary>///JScript Code/// </summary>Private Static ReadOnly string_jscriptsource =@"class Evaluator{public function eval (expr:string): String {return Eval (expr);}}";}

C # compilation Js-evaluator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.