From 635c414c1b1c05fdfa063cc7065c21403d09d99b Mon Sep 17 00:00:00 2001 From: de4dot Date: Sat, 7 Jan 2012 00:02:31 +0100 Subject: [PATCH] Update code to take a GenericInstanceMethod param --- .../methodsrewriter/TypeInstanceResolver.cs | 4 +- blocks/MemberRefInstance.cs | 48 +++++++++++++------ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/AssemblyData/methodsrewriter/TypeInstanceResolver.cs b/AssemblyData/methodsrewriter/TypeInstanceResolver.cs index c6593bfb..a903aaa9 100644 --- a/AssemblyData/methodsrewriter/TypeInstanceResolver.cs +++ b/AssemblyData/methodsrewriter/TypeInstanceResolver.cs @@ -74,8 +74,8 @@ namespace AssemblyData.methodsrewriter { return null; var git = methodReference.DeclaringType as GenericInstanceType; - if (git != null) - methodReference = MethodReferenceInstance.make(methodReference, git); + var gim = methodReference as GenericInstanceMethod; + methodReference = MethodReferenceInstance.make(methodReference, git, gim); foreach (var method in list) { if (ResolverUtils.compareMethods(method, methodReference)) diff --git a/blocks/MemberRefInstance.cs b/blocks/MemberRefInstance.cs index b929001c..f3d54a22 100644 --- a/blocks/MemberRefInstance.cs +++ b/blocks/MemberRefInstance.cs @@ -37,16 +37,18 @@ namespace de4dot.blocks { public class TypeReferenceInstance : RefInstance { TypeReference typeReference; GenericInstanceType git; + IGenericInstance gim; - public static TypeReference make(TypeReference typeReference, GenericInstanceType git) { - if (git == null) + public static TypeReference make(TypeReference typeReference, GenericInstanceType git, IGenericInstance gim = null) { + if (git == null && gim == null) return typeReference; - return new TypeReferenceInstance(typeReference, git).makeInstance(); + return new TypeReferenceInstance(typeReference, git, gim).makeInstance(); } - TypeReferenceInstance(TypeReference typeReference, GenericInstanceType git) { + TypeReferenceInstance(TypeReference typeReference, GenericInstanceType git, IGenericInstance gim) { this.typeReference = typeReference; this.git = git; + this.gim = gim; } // Returns same one if nothing was modified @@ -105,7 +107,7 @@ namespace de4dot.blocks { FunctionPointerType makeInstanceFunctionPointerType(FunctionPointerType a) { var rv = new FunctionPointerType(); - rv.function = MethodReferenceInstance.make(a.function, git); + rv.function = MethodReferenceInstance.make(a.function, git, gim); checkModified(a.function, rv.function); return rv; } @@ -118,10 +120,24 @@ namespace de4dot.blocks { } TypeReference makeInstanceGenericParameter(GenericParameter a) { - if (!MemberReferenceHelper.compareTypes(a.Owner as TypeReference, git.ElementType)) + switch (a.Type) { + case GenericParameterType.Type: + if (git == null || a.Position >= git.GenericArguments.Count || + !MemberReferenceHelper.compareTypes(git.ElementType, a.Owner as TypeReference)) { + return a; + } + modified = true; + return makeInstance(git.GenericArguments[a.Position]); + + case GenericParameterType.Method: + if (gim == null || a.Position >= gim.GenericArguments.Count) + return a; + modified = true; + return makeInstance(gim.GenericArguments[a.Position]); + + default: return a; - modified = true; - return makeInstance(git.GenericArguments[a.Position]); + } } OptionalModifierType makeInstanceOptionalModifierType(OptionalModifierType a) { @@ -155,13 +171,15 @@ namespace de4dot.blocks { public abstract class MultiTypeRefInstance : RefInstance { GenericInstanceType git; + IGenericInstance gim; - public MultiTypeRefInstance(GenericInstanceType git) { + public MultiTypeRefInstance(GenericInstanceType git, IGenericInstance gim = null) { this.git = git; + this.gim = gim; } protected TypeReference makeInstance(TypeReference tr) { - var type = TypeReferenceInstance.make(tr, git); + var type = TypeReferenceInstance.make(tr, git, gim); checkModified(type, tr); return type; } @@ -174,14 +192,14 @@ namespace de4dot.blocks { public class MethodReferenceInstance : MultiTypeRefInstance { MethodReference methodReference; - public static MethodReference make(MethodReference methodReference, GenericInstanceType git) { - if (git == null) + public static MethodReference make(MethodReference methodReference, GenericInstanceType git, IGenericInstance gim = null) { + if (git == null && gim == null) return methodReference; - return new MethodReferenceInstance(methodReference, git).makeInstance(); + return new MethodReferenceInstance(methodReference, git, gim).makeInstance(); } - MethodReferenceInstance(MethodReference methodReference, GenericInstanceType git) - : base(git) { + MethodReferenceInstance(MethodReference methodReference, GenericInstanceType git, IGenericInstance gim) + : base(git, gim) { this.methodReference = methodReference; }