Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJb Evain <jb@evain.net>2016-07-11 03:33:11 +0300
committerJb Evain <jb@evain.net>2016-07-11 03:33:11 +0300
commit3f203f8d2cbe7122517f5f080dcf9c02d8b05c22 (patch)
tree85be1e403226b7733e0a64f99758ed3c776cd421
parent042bdd2432705ae4c682743ff9740550dee3bead (diff)
Improve matching from import generic stack. Fix #278
That's not pretty, we should not match against strings. We should rather keep in the context the original method that we could compare, but as a quick fix, this will do.
-rw-r--r--Mono.Cecil/Import.cs22
1 files changed, 16 insertions, 6 deletions
diff --git a/Mono.Cecil/Import.cs b/Mono.Cecil/Import.cs
index fda6a9c..d1e9929 100644
--- a/Mono.Cecil/Import.cs
+++ b/Mono.Cecil/Import.cs
@@ -79,7 +79,7 @@ namespace Mono.Cecil {
if (candidate == null)
continue;
- if (method != candidate.Name)
+ if (method != NormalizeMethodName (candidate))
continue;
return candidate.GenericParameters [position];
@@ -88,6 +88,11 @@ namespace Mono.Cecil {
throw new InvalidOperationException ();
}
+ public string NormalizeMethodName (MethodReference method)
+ {
+ return method.DeclaringType.FullName + "." + method.Name;
+ }
+
public TypeReference TypeParameter (string type, int position)
{
for (int i = stack.Count - 1; i >= 0; i--) {
@@ -231,18 +236,23 @@ namespace Mono.Cecil {
throw new InvalidOperationException ();
if (type.DeclaringMethod != null)
- return context.MethodParameter (type.DeclaringMethod.Name, type.GenericParameterPosition);
+ return context.MethodParameter (NormalizeMethodName (type.DeclaringMethod), type.GenericParameterPosition);
if (type.DeclaringType != null)
- return context.TypeParameter (NormalizedFullName (type.DeclaringType), type.GenericParameterPosition);
+ return context.TypeParameter (NormalizeTypeFullName (type.DeclaringType), type.GenericParameterPosition);
throw new InvalidOperationException();
}
- private static string NormalizedFullName (Type type)
+ static string NormalizeMethodName (SR.MethodBase method)
+ {
+ return NormalizeTypeFullName (method.DeclaringType) + "." + method.Name;
+ }
+
+ static string NormalizeTypeFullName (Type type)
{
if (IsNestedType (type))
- return NormalizedFullName (type.DeclaringType) + "/" + type.Name;
+ return NormalizeTypeFullName (type.DeclaringType) + "/" + type.Name;
return type.FullName;
}
@@ -627,7 +637,7 @@ namespace Mono.Cecil {
var mvar_parameter = (GenericParameter) type;
if (mvar_parameter.DeclaringMethod == null)
throw new InvalidOperationException ();
- return context.MethodParameter (mvar_parameter.DeclaringMethod.Name, mvar_parameter.Position);
+ return context.MethodParameter (context.NormalizeMethodName (mvar_parameter.DeclaringMethod), mvar_parameter.Position);
}
throw new NotSupportedException (type.etype.ToString ());