public void Test() { Compilation comp = GetCompilation(SomeCode); EntryPointFinder finder = new EntryPointFinder(); foreach (SyntaxTree tree in comp.SyntaxTrees) { finder.Visit(tree.GetRoot()); } List <Node <Evaluation> > simGraphs = new List <Node <Evaluation> >(); foreach (MethodDeclarationSyntax entryPoint in finder.EntryPoints) { Simulator sim = new Simulator(comp, entryPoint); INamedTypeSymbol arr = comp.GetSpecialType(SpecialType.System_Array);//TODO - array as instance? sim.SimulateFrame(sim.EntryFrame, new Instance(arr, NodeKind.Root)); simGraphs.Add(sim.StaticInstance.Node); } int y = 0; }
private static async Task <ScriptState <object> > EmulateConsoleMainInvocation( ScriptState <object> state, StringBuilder buffer, ScriptOptions options, Budget budget) { var script = state.Script; var compiled = script.Compile(); if (compiled.FirstOrDefault(d => d.Descriptor.Id == "CS7022") != null && EntryPointType() is IMethodSymbol entryPointMethod) { // e.g. warning CS7022: The entry point of the program is global script code; ignoring 'Program.Main()' entry point. // add a line of code to call Main using reflection buffer.AppendLine( $@" typeof({entryPointMethod.ContainingType.Name}) .GetMethod(""Main"", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public) .Invoke(null, {ParametersForMain()});"); state = await Run(buffer, options, budget); } return(state); IMethodSymbol EntryPointType() => EntryPointFinder.FindEntryPoint( script.GetCompilation().GlobalNamespace); string ParametersForMain() => entryPointMethod.Parameters.Any() ? "new object[]{ new string[0] }" : "null"; }