|
|
|
@ -52,7 +52,7 @@ namespace ICSharpCode.ILSpy
@@ -52,7 +52,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
{ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
#if DEBUG
|
|
|
|
|
internal static IEnumerable<CSharpLanguage> GetDebugLanguages() |
|
|
|
|
{ |
|
|
|
|
DecompilerContext context = new DecompilerContext(ModuleDefinition.CreateModule("dummy", ModuleKind.Dll)); |
|
|
|
@ -71,7 +71,7 @@ namespace ICSharpCode.ILSpy
@@ -71,7 +71,7 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
showAllMembers = true |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
public override string Name |
|
|
|
|
{ |
|
|
|
@ -92,9 +92,51 @@ namespace ICSharpCode.ILSpy
@@ -92,9 +92,51 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
{ |
|
|
|
|
WriteCommentLine(output, TypeToString(method.DeclaringType, includeNamespace: true)); |
|
|
|
|
AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: method.DeclaringType, isSingleMember: true); |
|
|
|
|
if (method.IsConstructor && !method.IsStatic && !method.DeclaringType.IsValueType) { |
|
|
|
|
// also fields and other ctors so that the field initializers can be shown as such
|
|
|
|
|
AddFieldsAndCtors(codeDomBuilder, method.DeclaringType, method.IsStatic); |
|
|
|
|
RunTransformsAndGenerateCode(codeDomBuilder, output, options, new SelectCtorTransform(method)); |
|
|
|
|
} else { |
|
|
|
|
codeDomBuilder.AddMethod(method); |
|
|
|
|
RunTransformsAndGenerateCode(codeDomBuilder, output, options); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class SelectCtorTransform : IAstTransform |
|
|
|
|
{ |
|
|
|
|
readonly MethodDefinition ctorDef; |
|
|
|
|
|
|
|
|
|
public SelectCtorTransform(MethodDefinition ctorDef) |
|
|
|
|
{ |
|
|
|
|
this.ctorDef = ctorDef; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Run(AstNode compilationUnit) |
|
|
|
|
{ |
|
|
|
|
ConstructorDeclaration ctorDecl = null; |
|
|
|
|
foreach (var node in compilationUnit.Children) { |
|
|
|
|
ConstructorDeclaration ctor = node as ConstructorDeclaration; |
|
|
|
|
if (ctor != null) { |
|
|
|
|
if (ctor.Annotation<MethodDefinition>() == ctorDef) { |
|
|
|
|
ctorDecl = ctor; |
|
|
|
|
} else { |
|
|
|
|
// remove other ctors
|
|
|
|
|
ctor.Remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Remove any fields without initializers
|
|
|
|
|
FieldDeclaration fd = node as FieldDeclaration; |
|
|
|
|
if (fd != null && fd.Variables.All(v => v.Initializer.IsNull)) |
|
|
|
|
fd.Remove(); |
|
|
|
|
} |
|
|
|
|
if (ctorDecl.Initializer.ConstructorInitializerType == ConstructorInitializerType.This) { |
|
|
|
|
// remove all fields
|
|
|
|
|
foreach (var node in compilationUnit.Children) |
|
|
|
|
if (node is FieldDeclaration) |
|
|
|
|
node.Remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override void DecompileProperty(PropertyDefinition property, ITextOutput output, DecompilationOptions options) |
|
|
|
|
{ |
|
|
|
@ -108,8 +150,48 @@ namespace ICSharpCode.ILSpy
@@ -108,8 +150,48 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
{ |
|
|
|
|
WriteCommentLine(output, TypeToString(field.DeclaringType, includeNamespace: true)); |
|
|
|
|
AstBuilder codeDomBuilder = CreateAstBuilder(options, currentType: field.DeclaringType, isSingleMember: true); |
|
|
|
|
if (field.IsLiteral) { |
|
|
|
|
codeDomBuilder.AddField(field); |
|
|
|
|
RunTransformsAndGenerateCode(codeDomBuilder, output, options); |
|
|
|
|
} else { |
|
|
|
|
// also decompile ctors so that the field initializer can be shown
|
|
|
|
|
AddFieldsAndCtors(codeDomBuilder, field.DeclaringType, field.IsStatic); |
|
|
|
|
} |
|
|
|
|
RunTransformsAndGenerateCode(codeDomBuilder, output, options, new SelectFieldTransform(field)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes all top-level members except for the specified fields.
|
|
|
|
|
/// </summary>
|
|
|
|
|
sealed class SelectFieldTransform : IAstTransform |
|
|
|
|
{ |
|
|
|
|
readonly FieldDefinition field; |
|
|
|
|
|
|
|
|
|
public SelectFieldTransform(FieldDefinition field) |
|
|
|
|
{ |
|
|
|
|
this.field = field; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void Run(AstNode compilationUnit) |
|
|
|
|
{ |
|
|
|
|
foreach (var child in compilationUnit.Children) { |
|
|
|
|
if (child is AttributedNode) { |
|
|
|
|
if (child.Annotation<FieldDefinition>() != field) |
|
|
|
|
child.Remove(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void AddFieldsAndCtors(AstBuilder codeDomBuilder, TypeDefinition declaringType, bool isStatic) |
|
|
|
|
{ |
|
|
|
|
foreach (var field in declaringType.Fields) { |
|
|
|
|
if (field.IsStatic == isStatic) |
|
|
|
|
codeDomBuilder.AddField(field); |
|
|
|
|
} |
|
|
|
|
foreach (var ctor in declaringType.Methods) { |
|
|
|
|
if (ctor.IsConstructor && ctor.IsStatic == isStatic) |
|
|
|
|
codeDomBuilder.AddMethod(ctor); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override void DecompileEvent(EventDefinition ev, ITextOutput output, DecompilationOptions options) |
|
|
|
@ -127,11 +209,15 @@ namespace ICSharpCode.ILSpy
@@ -127,11 +209,15 @@ namespace ICSharpCode.ILSpy
|
|
|
|
|
RunTransformsAndGenerateCode(codeDomBuilder, output, options); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options) |
|
|
|
|
void RunTransformsAndGenerateCode(AstBuilder astBuilder, ITextOutput output, DecompilationOptions options, IAstTransform additionalTransform = null) |
|
|
|
|
{ |
|
|
|
|
astBuilder.RunTransformations(transformAbortCondition); |
|
|
|
|
if (options.DecompilerSettings.ShowXmlDocumentation) |
|
|
|
|
if (additionalTransform != null) { |
|
|
|
|
additionalTransform.Run(astBuilder.CompilationUnit); |
|
|
|
|
} |
|
|
|
|
if (options.DecompilerSettings.ShowXmlDocumentation) { |
|
|
|
|
AddXmlDocTransform.Run(astBuilder.CompilationUnit); |
|
|
|
|
} |
|
|
|
|
astBuilder.GenerateCode(output); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|