Boo.Lang.Compiler.TypeSystem.GenericsServices.GetMethodGenerity C# (CSharp) Méthode

GetMethodGenerity() public static méthode

public static GetMethodGenerity ( IMethod method ) : int
method IMethod
Résultat int
        public static int GetMethodGenerity(IMethod method)
        {
            IConstructedMethodInfo constructedInfo = method.ConstructedInfo;
            if (constructedInfo != null)
                return constructedInfo.GenericArguments.Length;

            IGenericMethodInfo genericInfo = method.GenericInfo;
            if (genericInfo != null)
                return genericInfo.GenericParameters.Length;

            return 0;
        }

Usage Example

Exemple #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));
        }