Browse Source

fix #556: ILSpy doesn't highlight uses of invoked delegates

pull/569/head
Siegfried Pammer 11 years ago
parent
commit
98f24c21e5
  1. 5
      ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs
  2. 13
      ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs
  3. 11
      ICSharpCode.Decompiler/CecilExtensions.cs

5
ICSharpCode.Decompiler/Ast/TextOutputFormatter.cs

@ -93,6 +93,11 @@ namespace ICSharpCode.Decompiler.Ast @@ -93,6 +93,11 @@ namespace ICSharpCode.Decompiler.Ast
{
memberRef = node.Parent.Annotation<MemberReference>();
}
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);
}

13
ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs

@ -195,7 +195,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms @@ -195,7 +195,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms
replacement = ame;
}
var expectedType = objectCreateExpression.Annotation<TypeInformation>().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 @@ -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)
{

11
ICSharpCode.Decompiler/CecilExtensions.cs

@ -359,5 +359,16 @@ namespace ICSharpCode.Decompiler @@ -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;
}
}
}

Loading…
Cancel
Save