示例#1
0
 public static GenericFuncContainer <MethodDefinition, bool> MethodReturnTypeComparer(TypeDefinition returnType)
 {
     return(new GenericFuncContainer <MethodDefinition, bool>(method => {
         TypeDefinition curReturnType = method.ReturnType.Resolve();
         if (curReturnType == null)
         {
             HelperClass.OnError(ErrorCode.RETURNTYPE_RESOLVE_ERROR, method.FullName, Environment.StackTrace);
             return false;
         }
         return curReturnType.Equals(returnType);
     }));
 }
示例#2
0
        public static bool RenameVirtualMethod(MethodDefinition method, string newName)
        {
            TypeDefinition[] parameters = new TypeDefinition[method.Parameters.Count];
            string           oldName    = method.Name;

            for (int i = 0; i < parameters.Length; i++)
            {
                parameters[i] = method.Parameters[i].ParameterType.Resolve();
                if (parameters[i] == null)
                {
                    HelperClass.OnError(ErrorCode.PARAMETER_RESOLVE_ERROR, i, method.FullName, Environment.StackTrace);
                    return(false);
                }
            }

            GenericFuncContainer <MethodDefinition, bool> vMethodComparer = CombinedComparer(
                MethodParametersComparer(parameters),
                MemberNameComparer <MethodDefinition>(method.Name),
                MethodAttributeComparer(Mono.Cecil.MethodAttributes.Virtual));

            TypeDefinition curBaseType = method.DeclaringType;

            while (curBaseType != null)
            {
                if (findMember <MethodDefinition>(null, curBaseType, true, false, vMethodComparer) == null)
                {
                    break;
                }
                TypeReference curBaseRef = curBaseType.BaseType;
                if (curBaseRef == null)
                {
                    break;
                }
                TypeDefinition curBaseDef = curBaseRef.Resolve();
                if (curBaseDef == null)
                {
                    break;
                }
                curBaseType = curBaseDef;
            }

            vMethodComparer = CombinedComparer(vMethodComparer, DeclaringTypeBaseTypeComparer <MethodDefinition>(curBaseType));
            //doesn't work for multiple assemblies
            foreach (MethodDefinition curVMethod in findMembers <MethodDefinition>(curBaseType.Module, null, vMethodComparer))
            {
                curVMethod.Name = newName;
            }
            return(true);
        }
示例#3
0
 public static GenericFuncContainer <MethodDefinition, bool> MethodParametersComparer(TypeDefinition[] parameterTypes)
 {
     return(new GenericFuncContainer <MethodDefinition, bool>(method => {
         if (method.Parameters.Count != parameterTypes.Length)
         {
             return false;
         }
         for (int i = 0; i < method.Parameters.Count; i++)
         {
             TypeDefinition curParameterType = method.Parameters[i].ParameterType.Resolve();
             if (curParameterType == null)
             {
                 HelperClass.OnError(ErrorCode.PARAMETER_RESOLVE_ERROR, i, method.FullName, Environment.StackTrace);
                 return false;
             }
             if (parameterTypes[i] != null && !curParameterType.Equals(parameterTypes[i]))
             {
                 return false;
             }
         }
         return true;
     }));
 }