コード例 #1
0
        public static List <ReferenceSegment> Decompile(TextEditor data, AssemblyLoader assemblyLoader, Func <CSharpDecompiler, SyntaxTree> decompile, DecompilerSettings settings = null, DecompileFlags flags = null)
        {
            settings = settings ?? GetDecompilerSettings(data, publicOnly: flags.PublicOnly);
            var csharpDecompiler = assemblyLoader.CSharpDecompiler;

            try
            {
                var syntaxTree = decompile(csharpDecompiler);
                if (!flags.MethodBodies)
                {
                    MethodBodyRemoveVisitor.RemoveMethodBodies(syntaxTree);
                }

                var         output      = new ColoredCSharpFormatter(data);
                TokenWriter tokenWriter = new TextTokenWriter(output, settings, csharpDecompiler.TypeSystem)
                {
                    FoldBraces = settings.FoldBraces
                };
                var formattingPolicy = settings.CSharpFormattingOptions;
                syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, formattingPolicy));
                output.SetDocumentData();
                return(output.ReferencedSegments);
            }
            catch (Exception e)
            {
                data.InsertText(data.Length, "/* decompilation failed: \n" + e + " */");
            }
            return(null);
        }
コード例 #2
0
        public static Task <List <ReferenceSegment> > DecompileAsync(TextEditor data, AssemblyLoader assemblyLoader, Func <CSharpDecompiler, SyntaxTree> decompile, DecompilerSettings settings = null, DecompileFlags flags = null)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            if (assemblyLoader == null)
            {
                throw new ArgumentNullException(nameof(assemblyLoader));
            }

            return(Task.Run(async delegate {
                settings = settings ?? GetDecompilerSettings(data, publicOnly: flags.PublicOnly);
                var csharpDecompiler = assemblyLoader.CSharpDecompiler;
                try {
                    var syntaxTree = decompile(csharpDecompiler);
                    if (!flags.MethodBodies)
                    {
                        MethodBodyRemoveVisitor.RemoveMethodBodies(syntaxTree);
                    }
                    return await Runtime.RunInMainThread(delegate {
                        if (data.IsDisposed)
                        {
                            return new List <ReferenceSegment> ();
                        }
                        var output = new ColoredCSharpFormatter(data);
                        TokenWriter tokenWriter = new TextTokenWriter(output, settings, csharpDecompiler.TypeSystem)
                        {
                            FoldBraces = settings.FoldBraces
                        };
                        var formattingPolicy = settings.CSharpFormattingOptions;
                        syntaxTree.AcceptVisitor(new CSharpOutputVisitor(tokenWriter, formattingPolicy));
                        output.SetDocumentData();
                        return output.ReferencedSegments;
                    });
                } catch (Exception e) {
                    await Runtime.RunInMainThread(delegate {
                        data.InsertText(data.Length, "/* decompilation failed: \n" + e + " */");
                    });
                }
                return new List <ReferenceSegment> ();
            }));
        }