using Mono.CSharp; using System; Evaluator eval = new Evaluator(new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter())); eval.Run("int Add(int x, int y) { return x + y; }"); Method addMethod = eval.GetMethod("Add"); int result = (int)addMethod.Invoke(null, new object[] { 2, 3 }); Console.WriteLine(result); // Output: 5
using Mono.CSharp; using System; Evaluator eval = new Evaluator(new CompilerContext(new CompilerSettings(), new ConsoleReportPrinter())); eval.Run("public void PrintHello() { Console.WriteLine(\"Hello, world!\"); }"); Method helloMethod = eval.GetMethod("PrintHello"); helloMethod.Invoke(null, null);This example creates a new method called "PrintHello" and then calls it. The method simply prints "Hello, world!" to the console. Package Library: Mono.CSharp is a part of the Mono Framework.