예제 #1
0
        private static IEnumerable <AssemblyClass> GenerateAssemblyMethodSource(string assemblyPath)
        {
            AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters(ReadingMode.Deferred)
            {
                ReadSymbols = true
            });
            AstBuilder astBuilder = null;

            foreach (var defmod in assemblyDefinition.Modules)
            {
                foreach (var typeInAssembly in defmod.Types)
                {
                    AssemblyClass klass = new AssemblyClass();
                    klass.name      = typeInAssembly.Name;
                    klass.namespase = typeInAssembly.Namespace;
                    astBuilder      = new AstBuilder(new DecompilerContext(assemblyDefinition.MainModule)
                    {
                        CurrentType = typeInAssembly
                    });
                    astBuilder.AddType(typeInAssembly);

                    StringWriter output = new StringWriter();
                    astBuilder.GenerateCode(new PlainTextOutput(output));
                    klass.source = output.ToString();
                    yield return(klass);
                }
            }
        }
예제 #2
0
        private static IEnumerable<AssemblyClass> GenerateAssemblyMethodSource(string assemblyPath)
        {
            AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly (assemblyPath, new ReaderParameters (ReadingMode.Deferred) { ReadSymbols = true });
            AstBuilder astBuilder = null;
            foreach (var defmod in assemblyDefinition.Modules) {
                foreach (var typeInAssembly in defmod.Types) {
                    AssemblyClass klass = new AssemblyClass ();
                    klass.name = typeInAssembly.Name;
                    klass.namespase = typeInAssembly.Namespace;
                    astBuilder = new AstBuilder (new DecompilerContext (assemblyDefinition.MainModule) { CurrentType = typeInAssembly });
                    astBuilder.AddType (typeInAssembly);

                    StringWriter output = new StringWriter ();
                    astBuilder.GenerateCode (new PlainTextOutput (output));
                    klass.source = output.ToString ();
                    yield return klass;
                }
            }
        }