diff --git a/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs b/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs index 2c4f56816..e7af6d26e 100644 --- a/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs +++ b/ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs @@ -93,6 +93,11 @@ namespace ICSharpCode.Decompiler.Ast { memberRef = node.Parent.Annotation(); } + if (node is IdentifierExpression && node.Role == Roles.TargetExpression && node.Parent is InvocationExpression && memberRef != null) { + var declaringType = memberRef.DeclaringType.Resolve(); + if (declaringType != null && declaringType.IsDelegate()) + return null; + } return FilterMemberReference(memberRef); } diff --git a/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs index 5fc7d0d29..0741466f9 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs @@ -195,7 +195,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms replacement = ame; } var expectedType = objectCreateExpression.Annotation().ExpectedType.Resolve(); - if (expectedType != null && !IsDelegate(expectedType)) { + if (expectedType != null && !expectedType.IsDelegate()) { var simplifiedDelegateCreation = (ObjectCreateExpression)objectCreateExpression.Clone(); simplifiedDelegateCreation.Arguments.Clear(); simplifiedDelegateCreation.Arguments.Add(replacement); @@ -204,17 +204,6 @@ namespace ICSharpCode.Decompiler.Ast.Transforms objectCreateExpression.ReplaceWith(replacement); return true; } - - static bool IsDelegate(TypeDefinition type) - { - if (type.BaseType != null && type.BaseType.Namespace == "System") { - if (type.BaseType.Name == "MulticastDelegate") - return true; - if (type.BaseType.Name == "Delegate" && type.Name != "MulticastDelegate") - return true; - } - return false; - } internal static bool IsPotentialClosure(DecompilerContext context, TypeDefinition potentialDisplayClass) { diff --git a/ICSharpCode.Decompiler/CecilExtensions.cs b/ICSharpCode.Decompiler/CecilExtensions.cs index b773c6247..0c7cb1e40 100644 --- a/ICSharpCode.Decompiler/CecilExtensions.cs +++ b/ICSharpCode.Decompiler/CecilExtensions.cs @@ -359,5 +359,16 @@ namespace ICSharpCode.Decompiler } return false; } + + public static bool IsDelegate(this TypeDefinition type) + { + if (type.BaseType != null && type.BaseType.Namespace == "System") { + if (type.BaseType.Name == "MulticastDelegate") + return true; + if (type.BaseType.Name == "Delegate" && type.Name != "MulticastDelegate") + return true; + } + return false; + } } }