public string Decompile(object @object) { if (@object == null) { return(String.Empty); } Language l = new CSharpLanguage(); ITextOutput output = new RtfTextOutput(); var options = new DecompilationOptions(); if (@object is AssemblyDefinition) { l.DecompileAssembly((AssemblyDefinition)@object, output, options); } else if (@object is TypeDefinition) { l.DecompileType((TypeDefinition)@object, output, options); } else if (@object is MethodDefinition) { l.DecompileMethod((MethodDefinition)@object, output, options); } else if (@object is FieldDefinition) { l.DecompileField((FieldDefinition)@object, output, options); } else if (@object is PropertyDefinition) { l.DecompileProperty((PropertyDefinition)@object, output, options); } else if (@object is EventDefinition) { l.DecompileEvent((EventDefinition)@object, output, options); } else if (@object is AssemblyNameReference) { output.Write("// Assembly Reference "); output.WriteDefinition(@object.ToString(), null); output.WriteLine(); } else if (@object is ModuleReference) { output.Write("// Module Reference "); output.WriteDefinition(@object.ToString(), null); output.WriteLine(); } else { output.Write(String.Format("// {0} ", @object.GetType().Name)); output.WriteDefinition(@object.ToString(), null); output.WriteLine(); } return(output.ToString()); }
public string Decompile(string language, object o) { if (o == null) { return(String.Empty); } Language l = CreateLanguage(language); if (l == null) { return(String.Format("Can't create language: {0}", language)); } ITextOutput output = new RtfTextOutput(); DecompilationOptions options = new DecompilationOptions(); if (o is AssemblyDefinition) { l.DecompileAssembly((AssemblyDefinition)o, output, options); } else if (o is TypeDefinition) { l.DecompileType((TypeDefinition)o, output, options); } else if (o is MethodDefinition) { l.DecompileMethod((MethodDefinition)o, output, options); } else if (o is FieldDefinition) { l.DecompileField((FieldDefinition)o, output, options); } else if (o is PropertyDefinition) { l.DecompileProperty((PropertyDefinition)o, output, options); } else if (o is EventDefinition) { l.DecompileEvent((EventDefinition)o, output, options); } else if (o is AssemblyNameReference) { output.Write("// Assembly Reference "); output.WriteDefinition(o.ToString(), null); output.WriteLine(); } else if (o is ModuleReference) { output.Write("// Module Reference "); output.WriteDefinition(o.ToString(), null); output.WriteLine(); } else { output.Write(String.Format("// {0} ", o.GetType().Name)); output.WriteDefinition(o.ToString(), null); output.WriteLine(); } return(output.ToString()); }