Exemplo n.º 1
0
        static bool MethodMatch(MethodReference candidate, MethodDefinition method)
        {
            var candidateDef = candidate.Resolve();

            if (!candidateDef.IsVirtual)
            {
                return(false);
            }

            if (candidate.HasParameters != method.HasParameters)
            {
                return(false);
            }

            if (candidate.Name != method.Name)
            {
                return(false);
            }

            if (candidate.HasGenericParameters != method.HasGenericParameters)
            {
                return(false);
            }

            // we need to track what the generic parameter represent - as we cannot allow it to
            // differ between the return type or any parameter
            if (!TypeMatch(candidate.GetReturnType(), method.GetReturnType()))
            {
                return(false);
            }

            if (!candidate.HasParameters)
            {
                return(true);
            }

            var cp = candidate.Parameters;
            var mp = method.Parameters;

            if (cp.Count != mp.Count)
            {
                return(false);
            }

            if (candidate.GenericParameters.Count != method.GenericParameters.Count)
            {
                return(false);
            }

            for (int i = 0; i < cp.Count; i++)
            {
                if (!TypeMatch(candidate.GetParameterType(i), method.GetParameterType(i)))
                {
                    return(false);
                }
            }

            return(true);
        }