Beispiel #1
0
        private static int Compare <T>(OverloadResolutionCandidate <T> x, OverloadResolutionCandidate <T> y, int argumentCount)
            where T : Signature
        {
            var betterConversionsInX = 0;
            var betterConversionsInY = 0;

            for (var i = 0; i < argumentCount; i++)
            {
                var cX = x.ArgumentConversions[i];
                var tX = x.Signature.GetParameterType(i);
                var cY = y.ArgumentConversions[i];
                var tY = y.Signature.GetParameterType(i);

                var comparison = Conversion.Compare(tX, cX, tY, cY);

                if (comparison < 0)
                {
                    betterConversionsInX++;
                }
                else if (comparison > 0)
                {
                    betterConversionsInY++;
                }
            }

            // NOTE: The roles are reversed here.
            return(-betterConversionsInX.CompareTo(betterConversionsInY));
        }
 public OverloadResolutionResult(OverloadResolutionCandidate <T> best, OverloadResolutionCandidate <T> selected, IEnumerable <OverloadResolutionCandidate <T> > candidates)
 {
     Best       = best;
     Selected   = selected;
     Candidates = candidates.ToImmutableArray();
 }
Beispiel #3
0
 private static bool IsApplicable <T>(OverloadResolutionCandidate <T> candidate, int argumentCount)
     where T : Signature
 {
     return(candidate.Signature.ParameterCount == argumentCount &&
            candidate.ArgumentConversions.All(c => c.IsImplicit));
 }
Beispiel #4
0
        private static void GetBestAndSelectedCandidate <T>(IEnumerable <OverloadResolutionCandidate <T> > candidates, out OverloadResolutionCandidate <T> best, out OverloadResolutionCandidate <T> selected)
            where T : Signature
        {
            best     = null;
            selected = null;

            foreach (var candidate in candidates.Where(c => c.IsSuitable))
            {
                if (best == null)
                {
                    best = selected = candidate;
                }
                else
                {
                    best = null;
                    return;
                }
            }
        }