Browse Source

Fix NRefactoryCecilMapper.GetMethod() for methods outside the current assembly.

pull/728/head
Daniel Grunwald 11 years ago
parent
commit
4fadba8f4f
  1. 39
      ICSharpCode.Decompiler/CSharp/NRefactoryCecilMapper.cs

39
ICSharpCode.Decompiler/CSharp/NRefactoryCecilMapper.cs

@ -20,6 +20,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using ICSharpCode.NRefactory.TypeSystem; using ICSharpCode.NRefactory.TypeSystem;
using ICSharpCode.NRefactory.TypeSystem.Implementation;
using Mono.Cecil; using Mono.Cecil;
namespace ICSharpCode.Decompiler.CSharp namespace ICSharpCode.Decompiler.CSharp
@ -69,11 +70,47 @@ namespace ICSharpCode.Decompiler.CSharp
} }
public IMethod GetMethod(MethodReference methodReference) public IMethod GetMethod(MethodReference methodReference)
{
var method = GetNonGenericMethod(methodReference.GetElementMethod());
// TODO: specialize the method
return method;
}
IMethod GetNonGenericMethod(MethodReference methodReference)
{ {
ITypeDefinition typeDef = GetType(methodReference.DeclaringType).GetDefinition(); ITypeDefinition typeDef = GetType(methodReference.DeclaringType).GetDefinition();
if (typeDef == null) if (typeDef == null)
return null; return null;
return typeDef.Methods.FirstOrDefault(m => GetCecil(m) == methodReference); IEnumerable<IMethod> methods;
if (methodReference.Name == ".ctor") {
methods = typeDef.GetConstructors();
} else if (methodReference.Name == ".cctor") {
return typeDef.Methods.FirstOrDefault(m => m.IsConstructor && m.IsStatic);
} else {
methods = typeDef.GetMethods(m => m.Name == methodReference.Name, GetMemberOptions.IgnoreInheritedMembers)
.Concat(typeDef.GetAccessors(m => m.Name == methodReference.Name, GetMemberOptions.IgnoreInheritedMembers));
}
foreach (var method in methods) {
if (GetCecil(method) == methodReference)
return method;
}
var parameterTypes = methodReference.Parameters.SelectArray(p => GetType(p.ParameterType));
foreach (var method in methods) {
if (parameterTypes.Length == method.Parameters.Count) {
bool signatureMatches = true;
for (int i = 0; i < parameterTypes.Length; i++) {
IType type1 = DummyTypeParameter.NormalizeAllTypeParameters(parameterTypes[i]);
IType type2 = DummyTypeParameter.NormalizeAllTypeParameters(method.Parameters[i].Type);
if (!type1.Equals(type2)) {
signatureMatches = false;
break;
}
}
if (signatureMatches)
return method;
}
}
return null;
} }
} }
} }

Loading…
Cancel
Save