示例#1
0
 public MethodNameGroup Get(MMethodDef method)
 {
     if (!method.IsVirtual())
     {
         throw new ApplicationException("Not a virtual method");
     }
     if (!methodGroups.TryGetValue(method, out var group))
     {
         methodGroups[method] = group = new MethodNameGroup();
         group.Add(method);
     }
     return(group);
 }
		public MethodNameGroup Get(MMethodDef method) {
			if (!method.IsVirtual())
				throw new ApplicationException("Not a virtual method");
			MethodNameGroup group;
			if (!methodGroups.TryGetValue(method, out group)) {
				methodGroups[method] = group = new MethodNameGroup();
				group.Add(method);
			}
			return group;
		}
示例#3
0
		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));
			}
		}
示例#4
0
		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;
		}
示例#5
0
		void RenameSpecialMethod(MMethodDef methodDef, string newName) {
			if (methodDef == null)
				return;
			if (methodDef.IsVirtual())
				return;
			RenameMethod(methodDef, newName);
		}