Don't add method to overrideMethods if it already overrides that iface method

This commit is contained in:
de4dot 2011-11-22 08:57:10 +01:00
parent 45cd6bf211
commit 33f9a466a1

View File

@ -134,15 +134,20 @@ namespace de4dot.renamer.asmmodules {
} }
} }
public void addMethod(MethodDef ifaceMethod, MethodDef classMethod) { // Returns the previous method, or null if none
public MethodDef addMethod(MethodDef ifaceMethod, MethodDef classMethod) {
if (!ifaceMethodToClassMethod.ContainsKey(ifaceMethod)) if (!ifaceMethodToClassMethod.ContainsKey(ifaceMethod))
throw new ApplicationException("Could not find interface method"); throw new ApplicationException("Could not find interface method");
MethodDef oldMethod;
ifaceMethodToClassMethod.TryGetValue(ifaceMethod, out oldMethod);
ifaceMethodToClassMethod[ifaceMethod] = classMethod; ifaceMethodToClassMethod[ifaceMethod] = classMethod;
return oldMethod;
} }
public void addMethodIfEmpty(MethodDef ifaceMethod, MethodDef classMethod) { public void addMethodIfEmpty(MethodDef ifaceMethod, MethodDef classMethod) {
if (ifaceMethodToClassMethod[ifaceMethod] == null) if (ifaceMethodToClassMethod[ifaceMethod] == null)
ifaceMethodToClassMethod[ifaceMethod] = classMethod; addMethod(ifaceMethod, classMethod);
} }
public override string ToString() { public override string ToString() {
@ -177,16 +182,18 @@ namespace de4dot.renamer.asmmodules {
interfaceMethods[key] = new InterfaceMethodInfo(iface); interfaceMethods[key] = new InterfaceMethodInfo(iface);
} }
public void addMethod(TypeInfo iface, MethodDef ifaceMethod, MethodDef classMethod) { // Returns the previous classMethod, or null if none
addMethod(iface.typeReference, ifaceMethod, classMethod); public MethodDef addMethod(TypeInfo iface, MethodDef ifaceMethod, MethodDef classMethod) {
return addMethod(iface.typeReference, ifaceMethod, classMethod);
} }
public void addMethod(TypeReference iface, MethodDef ifaceMethod, MethodDef classMethod) { // Returns the previous classMethod, or null if none
public MethodDef addMethod(TypeReference iface, MethodDef ifaceMethod, MethodDef classMethod) {
InterfaceMethodInfo info; InterfaceMethodInfo info;
var key = new TypeReferenceKey(iface); var key = new TypeReferenceKey(iface);
if (!interfaceMethods.TryGetValue(key, out info)) if (!interfaceMethods.TryGetValue(key, out info))
throw new ApplicationException("Could not find interface"); throw new ApplicationException("Could not find interface");
info.addMethod(ifaceMethod, classMethod); return info.addMethod(ifaceMethod, classMethod);
} }
public void addMethodIfEmpty(TypeInfo iface, MethodDef ifaceMethod, MethodDef classMethod) { public void addMethodIfEmpty(TypeInfo iface, MethodDef ifaceMethod, MethodDef classMethod) {
@ -554,8 +561,9 @@ namespace de4dot.renamer.asmmodules {
continue; continue;
} }
interfaceMethodInfos.addMethod(overrideMethod.DeclaringType, ifaceMethod, classMethod); var oldMethod = interfaceMethodInfos.addMethod(overrideMethod.DeclaringType, ifaceMethod, classMethod);
overrideMethods[classMethod] = true; if (oldMethod != classMethod)
overrideMethods[classMethod] = true;
} }
} }