Using system; using system.codedom.com; using microsoft.csharp; using system.reflection;
Public class evAl {static object getValue (string value) {string codenippet = "using system;" "/ r / n" "Namespace CZG {" "/ r / n" "public class eval" "/ r / n " " {" " / r / n " " public eval () {} " " / r / n " " public object getValue () " " / r / n " " {" "/ r / n" "RETURN" Value ";" "/ r / n" "}" "/ r / n"}} "
CodesnippetCompileUnit Unit = New CodesnippetCompileUnit (CODESNIPPET);
ICodeCompiler compiler = new CSharpCodeProvider () CreateCompiler ();. CompilerParameters para = new CompilerParameters (); para.ReferencedAssemblies.Add ( "System.dll"); para.GenerateInMemory = true; para.GenerateExecutable = false; para.OutputAssembly = " EVal.dll ";
Assembly asm = compiler.compileAssemblyfromdom (Para, Unit) .CompileDassembly
Type type = asm.gettype ("czg.eval"); methodInfo mi = type.getMethod ("getValue", bindingflags.public | bindingflags.instance);
Object obj = asm.createInstance ("czg.eval"); return mi.invoke (obj, null);} static void main () {console.writeline (Eval.GetValue ("125 -23")); console.writeline (Eval.getValue ("125 <23"));}} using microsoft.jscript; using microsoft.jscript.vsa; use microsoft.vsa; class myeval {/// /// Object X = Mathx.eval ("1 2 * 2-6 / 2"); /// code> /// example> public static object eval (string s) {vsaEngine v = new vsaEngine (); v.initvsaEngine (", new basevsasite ()); return microsoft.jscript.eval.jscriptevaluate (s, v);} static void main () {system.console.writeline (Eval (" 65-23 ")); }