|
|
|
@ -31,6 +31,7 @@ using ICSharpCode.Decompiler.IL.ControlFlow;
@@ -31,6 +31,7 @@ using ICSharpCode.Decompiler.IL.ControlFlow;
|
|
|
|
|
using ICSharpCode.Decompiler.IL.Transforms; |
|
|
|
|
using ICSharpCode.Decompiler.TypeSystem; |
|
|
|
|
using ICSharpCode.Decompiler.Util; |
|
|
|
|
using System.IO; |
|
|
|
|
|
|
|
|
|
namespace ICSharpCode.Decompiler.CSharp |
|
|
|
|
{ |
|
|
|
@ -284,6 +285,13 @@ namespace ICSharpCode.Decompiler.CSharp
@@ -284,6 +285,13 @@ namespace ICSharpCode.Decompiler.CSharp
|
|
|
|
|
rootNode.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
string SyntaxTreeToString(SyntaxTree syntaxTree) |
|
|
|
|
{ |
|
|
|
|
StringWriter w = new StringWriter(); |
|
|
|
|
syntaxTree.AcceptVisitor(new CSharpOutputVisitor(w, settings.CSharpFormattingOptions)); |
|
|
|
|
return w.ToString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile assembly and module attributes.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -297,6 +305,14 @@ namespace ICSharpCode.Decompiler.CSharp
@@ -297,6 +305,14 @@ namespace ICSharpCode.Decompiler.CSharp
|
|
|
|
|
return syntaxTree; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile assembly and module attributes.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string DecompileModuleAndAssemblyAttributesToString() |
|
|
|
|
{ |
|
|
|
|
return SyntaxTreeToString(DecompileModuleAndAssemblyAttributes()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DoDecompileModuleAndAssemblyAttributes(ITypeResolveContext decompilationContext, SyntaxTree syntaxTree) |
|
|
|
|
{ |
|
|
|
|
foreach (var a in typeSystem.Compilation.MainAssembly.AssemblyAttributes) { |
|
|
|
@ -345,6 +361,14 @@ namespace ICSharpCode.Decompiler.CSharp
@@ -345,6 +361,14 @@ namespace ICSharpCode.Decompiler.CSharp
|
|
|
|
|
return syntaxTree; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompiles the whole module into a single string.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string DecompileWholeModuleAsString() |
|
|
|
|
{ |
|
|
|
|
return SyntaxTreeToString(DecompileWholeModuleAsSingleFile()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile the given types.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -363,6 +387,47 @@ namespace ICSharpCode.Decompiler.CSharp
@@ -363,6 +387,47 @@ namespace ICSharpCode.Decompiler.CSharp
|
|
|
|
|
return syntaxTree; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile the given types.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definitions.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public string DecompileTypesAsString(IEnumerable<TypeDefinition> types) |
|
|
|
|
{ |
|
|
|
|
return SyntaxTreeToString(DecompileTypes(types)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile the given type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definition.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public SyntaxTree DecompileType(FullTypeName fullTypeName) |
|
|
|
|
{ |
|
|
|
|
var type = typeSystem.Compilation.FindType(fullTypeName).GetDefinition(); |
|
|
|
|
if (type == null) |
|
|
|
|
throw new InvalidOperationException($"Could not find type definition {fullTypeName} in type system."); |
|
|
|
|
var decompilationContext = new SimpleTypeResolveContext(typeSystem.MainAssembly); |
|
|
|
|
syntaxTree = new SyntaxTree(); |
|
|
|
|
definedSymbols = new HashSet<string>(); |
|
|
|
|
DoDecompileTypes(new[] { typeSystem.GetCecil(type) }, decompilationContext, syntaxTree); |
|
|
|
|
RunTransforms(syntaxTree, decompilationContext); |
|
|
|
|
return syntaxTree; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile the given type.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// Unlike Decompile(IMemberDefinition[]), this method will add namespace declarations around the type definition.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
public string DecompileTypeAsString(FullTypeName fullTypeName) |
|
|
|
|
{ |
|
|
|
|
return SyntaxTreeToString(DecompileType(fullTypeName)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile the specified types and/or members.
|
|
|
|
|
/// </summary>
|
|
|
|
@ -427,6 +492,22 @@ namespace ICSharpCode.Decompiler.CSharp
@@ -427,6 +492,22 @@ namespace ICSharpCode.Decompiler.CSharp
|
|
|
|
|
return syntaxTree; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile the specified types and/or members.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string DecompileAsString(params IMemberDefinition[] definitions) |
|
|
|
|
{ |
|
|
|
|
return SyntaxTreeToString(Decompile(definitions)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Decompile the specified types and/or members.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string DecompileAsString(IList<IMemberDefinition> definitions) |
|
|
|
|
{ |
|
|
|
|
return SyntaxTreeToString(Decompile(definitions)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
IEnumerable<EntityDeclaration> AddInterfaceImplHelpers(EntityDeclaration memberDecl, MethodDefinition methodDef, |
|
|
|
|
TypeSystemAstBuilder astBuilder) |
|
|
|
|
{ |
|
|
|
|