Example #1
0
    public void Issue_185_Referencing()
    {
        lib::CSScriptLib.CSScript.EvaluatorConfig.DebugBuild = true;

        var root_class_name = $"script_{System.Guid.NewGuid()}".Replace("-", "");

        var info = new css.CompileInfo {
            RootClass = root_class_name, PreferLoadingFromFile = true
        };

        var printer_asm = css.CSScript.Evaluator
                          .CompileCode(@"using System;
                                                     public class Printer
                                                     {
                                                         public void Print() => Console.Write(""Printing..."");
                                                     }", info);

        dynamic script = css.CSScript.Evaluator
                         .ReferenceAssembly(printer_asm)
                         .LoadMethod($"using static {root_class_name};" + @"
                                                   void Test()
                                                   {
                                                       new Printer().Print();
                                                   }");

        script.Test();
    }
Example #2
0
    public void Issue_185()
    {
        lib::CSScriptLib.CSScript.EvaluatorConfig.DebugBuild = true;

        var code2 = @"
     using System;
     using System.Collections.Generic;
     using System.Linq;

     public class Usings
     {
         static void Main(string[] args)
         {
             var x = new List<int> {1, 2, 3, 4, 5};
             var y = Enumerable.Range(0, 5);

             x.ForEach(Console.WriteLine);
             var z = y.First();
             Console.WriteLine(z);
         }
     }";

        var info = new css.CompileInfo {
            RootClass = "code2", AssemblyFile = "code2"
        };

        css.CSScript.Evaluator.CompileCode(code2, info);

        dynamic script = css.CSScript.Evaluator
                         .ReferenceAssembly(info.AssemblyFile)
                         .CompileMethod(@"using static code2;
                                             Usings Test()
                                             {
                                                 return new Usings();
                                             }")
                         .CreateObject("*");

        script.Test();
    }