void renameMethod(MMethodDef methodDef) { if (methodDef.isVirtual()) throw new ApplicationException("Can't rename virtual methods here"); if (!canRenameMethod(methodDef)) return; var info = method(methodDef); if (info.renamed) return; info.renamed = true; var checker = NameChecker; // PInvoke methods' EntryPoint is always valid. It has to, so always rename. bool isValidName = NameChecker.isValidMethodName(info.oldName); bool isExternPInvoke = methodDef.MethodDef.ImplMap != null && methodDef.MethodDef.RVA == 0; if (!isValidName || isExternPInvoke) { INameCreator nameCreator = null; string newName = info.suggestedName; string newName2; if (methodDef.MethodDef.ImplMap != null && !string.IsNullOrEmpty(newName2 = getPinvokeName(methodDef))) newName = newName2; else if (methodDef.isStatic()) nameCreator = variableNameState.staticMethodNameCreator; else nameCreator = variableNameState.instanceMethodNameCreator; if (!string.IsNullOrEmpty(newName)) nameCreator = new NameCreator2(newName); renameMethod(methodDef, variableNameState.getNewMethodName(info.oldName, nameCreator)); } }
bool canRenameMethod(MMethodDef methodDef) { var methodInfo = method(methodDef); if (methodDef.isStatic()) { if (methodInfo.oldName == ".cctor") return false; } else if (methodDef.isVirtual()) { if (DotNetUtils.derivesFromDelegate(type.TypeDef)) { switch (methodInfo.oldName) { case "BeginInvoke": case "EndInvoke": case "Invoke": return false; } } } else { if (methodInfo.oldName == ".ctor") return false; } return true; }