Update code to take a GenericInstanceMethod param

This commit is contained in:
de4dot 2012-01-07 00:02:31 +01:00
parent e0295980f5
commit 635c414c1b
2 changed files with 35 additions and 17 deletions

View File

@ -74,8 +74,8 @@ namespace AssemblyData.methodsrewriter {
return null; return null;
var git = methodReference.DeclaringType as GenericInstanceType; var git = methodReference.DeclaringType as GenericInstanceType;
if (git != null) var gim = methodReference as GenericInstanceMethod;
methodReference = MethodReferenceInstance.make(methodReference, git); methodReference = MethodReferenceInstance.make(methodReference, git, gim);
foreach (var method in list) { foreach (var method in list) {
if (ResolverUtils.compareMethods(method, methodReference)) if (ResolverUtils.compareMethods(method, methodReference))

View File

@ -37,16 +37,18 @@ namespace de4dot.blocks {
public class TypeReferenceInstance : RefInstance { public class TypeReferenceInstance : RefInstance {
TypeReference typeReference; TypeReference typeReference;
GenericInstanceType git; GenericInstanceType git;
IGenericInstance gim;
public static TypeReference make(TypeReference typeReference, GenericInstanceType git) { public static TypeReference make(TypeReference typeReference, GenericInstanceType git, IGenericInstance gim = null) {
if (git == null) if (git == null && gim == null)
return typeReference; 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.typeReference = typeReference;
this.git = git; this.git = git;
this.gim = gim;
} }
// Returns same one if nothing was modified // Returns same one if nothing was modified
@ -105,7 +107,7 @@ namespace de4dot.blocks {
FunctionPointerType makeInstanceFunctionPointerType(FunctionPointerType a) { FunctionPointerType makeInstanceFunctionPointerType(FunctionPointerType a) {
var rv = new FunctionPointerType(); var rv = new FunctionPointerType();
rv.function = MethodReferenceInstance.make(a.function, git); rv.function = MethodReferenceInstance.make(a.function, git, gim);
checkModified(a.function, rv.function); checkModified(a.function, rv.function);
return rv; return rv;
} }
@ -118,10 +120,24 @@ namespace de4dot.blocks {
} }
TypeReference makeInstanceGenericParameter(GenericParameter a) { 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; return a;
}
modified = true; modified = true;
return makeInstance(git.GenericArguments[a.Position]); 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;
}
} }
OptionalModifierType makeInstanceOptionalModifierType(OptionalModifierType a) { OptionalModifierType makeInstanceOptionalModifierType(OptionalModifierType a) {
@ -155,13 +171,15 @@ namespace de4dot.blocks {
public abstract class MultiTypeRefInstance : RefInstance { public abstract class MultiTypeRefInstance : RefInstance {
GenericInstanceType git; GenericInstanceType git;
IGenericInstance gim;
public MultiTypeRefInstance(GenericInstanceType git) { public MultiTypeRefInstance(GenericInstanceType git, IGenericInstance gim = null) {
this.git = git; this.git = git;
this.gim = gim;
} }
protected TypeReference makeInstance(TypeReference tr) { protected TypeReference makeInstance(TypeReference tr) {
var type = TypeReferenceInstance.make(tr, git); var type = TypeReferenceInstance.make(tr, git, gim);
checkModified(type, tr); checkModified(type, tr);
return type; return type;
} }
@ -174,14 +192,14 @@ namespace de4dot.blocks {
public class MethodReferenceInstance : MultiTypeRefInstance { public class MethodReferenceInstance : MultiTypeRefInstance {
MethodReference methodReference; MethodReference methodReference;
public static MethodReference make(MethodReference methodReference, GenericInstanceType git) { public static MethodReference make(MethodReference methodReference, GenericInstanceType git, IGenericInstance gim = null) {
if (git == null) if (git == null && gim == null)
return methodReference; return methodReference;
return new MethodReferenceInstance(methodReference, git).makeInstance(); return new MethodReferenceInstance(methodReference, git, gim).makeInstance();
} }
MethodReferenceInstance(MethodReference methodReference, GenericInstanceType git) MethodReferenceInstance(MethodReference methodReference, GenericInstanceType git, IGenericInstance gim)
: base(git) { : base(git, gim) {
this.methodReference = methodReference; this.methodReference = methodReference;
} }