private static List <TreeItem <MemberInfo> > Collect(string code) { var assemblyName = Guid.NewGuid().ToString(); var syntaxTree = CSharpCompiler.ParseText(code); var(_, assembly) = CSharpCompiler.Compile(assemblyName, syntaxTree); var syntaxItems = CSharpHelper.CollectSyntax(syntaxTree.GetRoot()); return(CSharpHelper.CollectMembers(assembly, syntaxItems)); }
private static List <Disassembler> GetFileDisassemblers(DisassembleFileOptions options, MessageWriter writer) { var begin = DateTime.Now; // Parsing writer.Write("; Parsing from file ... "); var syntaxTree = CSharpCompiler.ParseFrom(options.FilePath); var parsed = DateTime.Now; writer.WriteLine($"done. ({Diff(begin, parsed)})"); // Compiling writer.Write("; Compiling ... "); var compilationOptions = new CompilationOptions { SaveAssembly = options.SaveAssembly, DisableOptimization = options.DisableOptimization }; var assemblyName = Path.GetFileNameWithoutExtension(options.FilePath); var(_, assembly) = CSharpCompiler.Compile(assemblyName, syntaxTree, compilationOptions); var compiled = DateTime.Now; writer.WriteLine($"done. ({Diff(parsed, compiled)})"); // Analyzing writer.Write("; Analyzing ... "); var syntaxItems = CSharpHelper.CollectSyntax(syntaxTree.GetRoot()); var memberItems = CSharpHelper.CollectMembers(assembly, syntaxItems); var disassemblers = memberItems.Select(Disassembler.Create).ToList(); var analyzed = DateTime.Now; writer.WriteLine($"done. ({Diff(compiled, analyzed)})"); writer.WriteLine(""); return(disassemblers); }
private static List <TreeItem <CSharpSyntaxNode> > Collect(string code) { var syntaxTree = CSharpSyntaxTree.ParseText(code); return(CSharpHelper.CollectSyntax(syntaxTree.GetRoot())); }