GetMethodGenerity() public static method

public static GetMethodGenerity ( IMethod method ) : int
method IMethod
return int
Ejemplo n.º 1
0
        private int BetterCandidate(Candidate c1, Candidate c2)
        {
            if (c1 == c2)
            {
                return(0);
            }

            int result = Math.Sign(TotalScore(c1) - TotalScore(c2));

            if (result != 0)
            {
                return(result);
            }

            // Prefer methods declared on deeper types
            result =
                c1.Method.DeclaringType.GetTypeDepth() -
                c2.Method.DeclaringType.GetTypeDepth();

            if (result != 0)
            {
                return(result);
            }

            // Prefer methods with less generic parameters
            result =
                GenericsServices.GetMethodGenerity(c2.Method) -
                GenericsServices.GetMethodGenerity(c1.Method);

            if (result != 0)
            {
                return(result);
            }

            // --- Tie breaking mode! ---

            // Non-expanded methods are better than expanded ones
            if (!c1.Expanded && c2.Expanded)
            {
                return(1);
            }
            if (c1.Expanded && !c2.Expanded)
            {
                return(-1);
            }

            // An expanded method with more fixed parameters is better
            result = c1.Parameters.Length - c2.Parameters.Length;
            if (result != 0)
            {
                return(result);
            }

            // As a last means of breaking this desperate tie, we select the
            // "more specific" candidate, if one exists
            return(MoreSpecific(c1, c2));
        }