public static string PrintCSharp(this MethodDefinition self) { try { var textoutput = new ICSharpCode.Decompiler.PlainTextOutput(); var options = new ICSharpCode.ILSpy.DecompilationOptions(); var lang = new ICSharpCode.ILSpy.CSharpLanguage(); lang.DecompileMethod(self, textoutput, options); return textoutput.ToString(); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ForegroundColor = ConsoleColor.Gray; return ex.Message; } }
public static string PrintCSharp(this MethodDefinition self) { try { var textoutput = new ICSharpCode.Decompiler.PlainTextOutput(); var options = new ICSharpCode.ILSpy.DecompilationOptions(); var lang = new ICSharpCode.ILSpy.CSharpLanguage(); lang.DecompileMethod(self, textoutput, options); return(textoutput.ToString()); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ForegroundColor = ConsoleColor.Gray; return(ex.Message); } }
static void Main(string[] args) { string assemblyPath = @"C:\build\main\i386\debug\bin\TradingTechnologies.TTAPI.dll"; string outputPath = @"C:\build\main\i386\debug\bin\TradingTechnologies.TTAPI.dll.public_interface.txt"; var decompilationOptions = new ICSharpCode.ILSpy.DecompilationOptions() { DecompilerSettings = new ICSharpCode.Decompiler.DecompilerSettings() { ShowXmlDocumentation = false, FullyQualifyAmbiguousTypeNames = true, OnlyPublicAndProtected = true, } }; var assemblyResolver = new MyAssemblyResolver(assemblyPath); var asm = assemblyResolver.ReadAssembly(assemblyPath); var csharpLang = new ICSharpCode.ILSpy.CSharpLanguage(); using(var writer = new System.IO.StreamWriter(outputPath)) { var output = new ICSharpCode.Decompiler.PlainTextOutput(writer); foreach (var module in asm.Modules.OrderBy(m => m.Name)) { foreach (var type in module.Types.Where(t => isValidNamespace(t) && t.IsPublic)) { output.WriteLine(); output.Write("//===================================================================="); output.WriteLine(); output.Write("// "); output.Write(type.FullName); output.WriteLine(); output.WriteLine(); csharpLang.DecompileType(type, output, decompilationOptions); output.WriteLine(); } } //csharpLang.DecompileAssembly(asm, output, decompilationOptions); } }