Exemplo n.º 1
0
        void renameMethod(MethodDef 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;

            if (!NameChecker.isValidMethodName(info.oldName)) {
                INameCreator nameCreator = null;
                string newName = info.suggestedName;
                if (methodDef.MethodDefinition.PInvokeInfo != null)
                    newName = getPinvokeName(methodDef);
                else if (methodDef.isStatic())
                    nameCreator = variableNameState.staticMethodNameCreator;
                else
                    nameCreator = variableNameState.instanceMethodNameCreator;
                if (newName != null)
                    nameCreator = new NameCreator2(newName);
                renameMethod(methodDef, variableNameState.getNewMethodName(info.oldName, nameCreator));
            }
        }
Exemplo n.º 2
0
 bool canRenameMethod(MethodDef methodDef)
 {
     var methodInfo = method(methodDef);
     if (methodDef.isStatic()) {
         if (methodInfo.oldName == ".cctor")
             return false;
     }
     else if (methodDef.isVirtual()) {
         if (DotNetUtils.derivesFromDelegate(type.TypeDefinition)) {
             switch (methodInfo.oldName) {
             case "BeginInvoke":
             case "EndInvoke":
             case "Invoke":
                 return false;
             }
         }
     }
     else {
         if (methodInfo.oldName == ".ctor")
             return false;
     }
     return true;
 }