/// <summary>
 /// Rename the given method and all references to it from code.
 /// </summary>
 private void Rename(MethodDefinition method, string newName)
 {
     methodReferences = methodReferences ?? InterfaceHelper.GetReachableMethodReferencesByName(reachableMethods);
     var resolver = new GenericsResolver(method.DeclaringType);
     foreach (var methodRef in methodReferences[method.Name])
     {
         if (ReferenceEquals(method, methodRef))
             continue;
         if (methodRef.AreSameIncludingDeclaringType(method, resolver.Resolve))
         {
             methodRef.Name = newName;
         }
     }
     method.SetName(newName);
 }
Esempio n. 2
0
        /// <summary>
        /// Rename the given method and all references to it from code.
        /// 
        /// Note that the passed lookup will not be accurate after completion of this method.
        /// If you rename methods multiple times, but know that you will rename each single method
        /// only once, this should not be a problem.
        /// </summary>
        public static void Rename(MethodDefinition method, string newName, ILookup<string, MethodReference> reachableMethodReferencesByMethodName)
        {
            var resolver = new GenericsResolver(method.DeclaringType);

            // Rename reference to method
            foreach (var methodRef in reachableMethodReferencesByMethodName[method.Name])
            {
                if (!ReferenceEquals(methodRef, method) && methodRef.AreSameIncludingDeclaringType(method, resolver.Resolve))
                {
                    methodRef.Name = newName;
                }
            }
            // Rename method itself
            method.SetName(newName);
        }