Browse Source

Decompile delegates into a delegate declaration instead of a type declaration.

pull/100/head
Daniel Grunwald 15 years ago
parent
commit
88160e9777
  1. 31
      ICSharpCode.Decompiler/Ast/AstBuilder.cs
  2. 2
      ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs
  3. 2
      ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributes.cs

31
ICSharpCode.Decompiler/Ast/AstBuilder.cs

@ -123,7 +123,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -123,7 +123,7 @@ namespace ICSharpCode.Decompiler.Ast
public void AddType(TypeDefinition typeDef)
{
TypeDeclaration astType = CreateType(typeDef);
var astType = CreateType(typeDef);
NamespaceDeclaration astNS = GetCodeNamespace(typeDef.Namespace);
if (astNS != null) {
astNS.AddChild(astType, NamespaceDeclaration.MemberRole);
@ -153,7 +153,12 @@ namespace ICSharpCode.Decompiler.Ast @@ -153,7 +153,12 @@ namespace ICSharpCode.Decompiler.Ast
astCompileUnit.AddChild(CreateEvent(ev), CompilationUnit.MemberRole);
}
public TypeDeclaration CreateType(TypeDefinition typeDef)
/// <summary>
/// Creates the AST for a type definition.
/// </summary>
/// <param name="typeDef"></param>
/// <returns>TypeDeclaration or DelegateDeclaration.</returns>
public AttributedNode CreateType(TypeDefinition typeDef)
{
TypeDefinition oldCurrentType = context.CurrentType;
context.CurrentType = typeDef;
@ -183,13 +188,13 @@ namespace ICSharpCode.Decompiler.Ast @@ -183,13 +188,13 @@ namespace ICSharpCode.Decompiler.Ast
astType.Constraints.AddRange(MakeConstraints(genericParameters));
// Nested types
foreach(TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
foreach (TypeDefinition nestedTypeDef in typeDef.NestedTypes) {
if (MemberIsHidden(nestedTypeDef, context.Settings))
continue;
astType.AddChild(CreateType(nestedTypeDef), TypeDeclaration.MemberRole);
}
AttributedNode result = astType;
if (typeDef.IsEnum) {
long expectedEnumMemberValue = 0;
bool forcePrintingInitializers = IsFlagsEnum(typeDef);
@ -210,6 +215,21 @@ namespace ICSharpCode.Decompiler.Ast @@ -210,6 +215,21 @@ namespace ICSharpCode.Decompiler.Ast
astType.AddChild(enumMember, TypeDeclaration.MemberRole);
}
}
} else if (typeDef.BaseType != null && typeDef.BaseType.FullName == "System.MulticastDelegate") {
DelegateDeclaration dd = new DelegateDeclaration();
dd.Modifiers = astType.Modifiers & ~Modifiers.Sealed;
dd.Name = astType.Name;
dd.AddAnnotation(typeDef);
astType.Attributes.MoveTo(dd.Attributes);
astType.TypeParameters.MoveTo(dd.TypeParameters);
astType.Constraints.MoveTo(dd.Constraints);
foreach (var m in typeDef.Methods) {
if (m.Name == "Invoke") {
dd.ReturnType = ConvertType(m.ReturnType, m.MethodReturnType);
dd.Parameters.AddRange(MakeParameters(m.Parameters));
}
}
result = dd;
} else {
// Base type
if (typeDef.BaseType != null && !typeDef.IsValueType && typeDef.BaseType.FullName != "System.Object") {
@ -223,7 +243,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -223,7 +243,7 @@ namespace ICSharpCode.Decompiler.Ast
}
context.CurrentType = oldCurrentType;
return astType;
return result;
}
public void Transform(IAstTransform transform)
@ -704,6 +724,7 @@ namespace ICSharpCode.Decompiler.Ast @@ -704,6 +724,7 @@ namespace ICSharpCode.Decompiler.Ast
CustomEventDeclaration CreateEvent(EventDefinition eventDef)
{
CustomEventDeclaration astEvent = new CustomEventDeclaration();
ConvertCustomAttributes(astEvent, eventDef);
astEvent.AddAnnotation(eventDef);
astEvent.Name = CleanName(eventDef.Name);
astEvent.ReturnType = ConvertType(eventDef.EventType, eventDef);

2
ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributeSamples.cs

@ -46,7 +46,7 @@ namespace AttributeWithTypeArgument @@ -46,7 +46,7 @@ namespace AttributeWithTypeArgument
[AttributeUsage(AttributeTargets.All)]
public class MyTypeAttribute : Attribute
{
public MyTypeAttribute(Type t) : base()
public MyTypeAttribute(Type t)
{
}
}

2
ICSharpCode.Decompiler/Tests/CustomAttributes/S_CustomAttributes.cs

@ -20,7 +20,7 @@ namespace aa @@ -20,7 +20,7 @@ namespace aa
[AttributeUsage(AttributeTargets.All)]
public class MyAttribute : Attribute
{
public MyAttribute(CustomAtributes.EnumWithFlag en) : base()
public MyAttribute(CustomAtributes.EnumWithFlag en)
{
}
}

Loading…
Cancel
Save