diff --git a/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs b/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs index d915c0bd9..f264046f9 100644 --- a/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs +++ b/ICSharpCode.Decompiler/Ast/Transforms/DelegateConstruction.cs @@ -173,11 +173,11 @@ namespace ICSharpCode.Decompiler.Ast.Transforms if (stmt.Variables.Count() != 1) continue; var variable = stmt.Variables.Single(); - TypeDefinition type = stmt.Type.Annotation(); + TypeDefinition type = stmt.Type.Annotation().ResolveWithinSameModule(); if (!IsPotentialClosure(context, type)) continue; ObjectCreateExpression oce = variable.Initializer as ObjectCreateExpression; - if (oce == null || oce.Type.Annotation() != type || oce.Arguments.Any() || !oce.Initializer.IsNull) + if (oce == null || oce.Type.Annotation().ResolveWithinSameModule() != type || oce.Arguments.Any() || !oce.Initializer.IsNull) continue; // Looks like we found a display class creation. Now let's verify that the variable is used only for field accesses: bool ok = true; @@ -222,7 +222,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms isParameter = parameterOccurrances.Count(c => c == param) == 1; } if (isParameter) { - dict[m.Get("left").Single().Annotation()] = right; + dict[m.Get("left").Single().Annotation().ResolveWithinSameModule()] = right; cur.Remove(); } else { break; @@ -247,7 +247,7 @@ namespace ICSharpCode.Decompiler.Ast.Transforms if (identExpr.Identifier == variable.Name) { MemberReferenceExpression mre = (MemberReferenceExpression)identExpr.Parent; AstNode replacement; - if (dict.TryGetValue(mre.Annotation(), out replacement)) { + if (dict.TryGetValue(mre.Annotation().ResolveWithinSameModule(), out replacement)) { mre.ReplaceWith(replacement.Clone()); } } diff --git a/ICSharpCode.Decompiler/CecilExtensions.cs b/ICSharpCode.Decompiler/CecilExtensions.cs index 2280eba14..38e21e100 100644 --- a/ICSharpCode.Decompiler/CecilExtensions.cs +++ b/ICSharpCode.Decompiler/CecilExtensions.cs @@ -159,6 +159,14 @@ namespace ICSharpCode.Decompiler return accessorMethods; } + public static TypeDefinition ResolveWithinSameModule(this TypeReference type) + { + if (type != null && type.GetElementType().Module == type.Module) + return type.Resolve(); + else + return null; + } + public static FieldDefinition ResolveWithinSameModule(this FieldReference field) { if (field != null && field.DeclaringType.GetElementType().Module == field.Module)