Пример #1
0
        internal static Candidate GetPreferredCandidate(MethodCandidate one, MethodCandidate two, CallTypes callType, MetaObject[] actualTypes)
        {
            Candidate cmpParams = ParameterWrapper.GetPreferredParameters(one.Parameters, two.Parameters, actualTypes);

            if (cmpParams.Chosen())
            {
                return(cmpParams);
            }

            Candidate ret = MethodTarget.CompareEquivalentParameters(one.Target, two.Target);

            if (ret.Chosen())
            {
                return(ret);
            }

            if (CompilerHelpers.IsStatic(one.Target.Method) && !CompilerHelpers.IsStatic(two.Target.Method))
            {
                return(callType == CallTypes.ImplicitInstance ? Candidate.Two : Candidate.One);
            }
            else if (!CompilerHelpers.IsStatic(one.Target.Method) && CompilerHelpers.IsStatic(two.Target.Method))
            {
                return(callType == CallTypes.ImplicitInstance ? Candidate.One : Candidate.Two);
            }

            return(Candidate.Equivalent);
        }
Пример #2
0
        private static Candidate GetPreferredParameter(ParameterWrapper candidateOne, ParameterWrapper candidateTwo)
        {
            Assert.NotNull(candidateOne, candidateTwo);

            if (candidateOne._binder.ParametersEquivalent(candidateOne, candidateTwo))
            {
                return(Candidate.Equivalent);
            }

            Type t1 = candidateOne.Type;
            Type t2 = candidateTwo.Type;

            if (candidateOne._binder.CanConvertFrom(t2, candidateOne, NarrowingLevel.None))
            {
                if (candidateOne._binder.CanConvertFrom(t1, candidateTwo, NarrowingLevel.None))
                {
                    return(Candidate.Ambiguous);
                }
                else
                {
                    return(Candidate.Two);
                }
            }

            if (candidateOne._binder.CanConvertFrom(t1, candidateTwo, NarrowingLevel.None))
            {
                return(Candidate.One);
            }

            // Special additional rules to order numeric value types
            Candidate preferred = candidateOne._binder.PreferConvert(t1, t2);

            if (preferred.Chosen())
            {
                return(preferred);
            }

            preferred = candidateOne._binder.PreferConvert(t2, t1).TheOther();
            if (preferred.Chosen())
            {
                return(preferred);
            }

            return(Candidate.Ambiguous);
        }
Пример #3
0
        private static Candidate GetPreferredParameter(ParameterWrapper candidateOne, ParameterWrapper candidateTwo, MetaObject actualType)
        {
            Assert.NotNull(candidateOne, candidateTwo, actualType);

            if (candidateOne._binder.ParametersEquivalent(candidateOne, candidateTwo))
            {
                return(Candidate.Equivalent);
            }

            for (NarrowingLevel curLevel = NarrowingLevel.None; curLevel <= NarrowingLevel.All; curLevel++)
            {
                Candidate candidate = candidateOne._binder.SelectBestConversionFor(actualType.LimitType, candidateOne, candidateTwo, curLevel);
                if (candidate.Chosen())
                {
                    return(candidate);
                }
            }

            return(GetPreferredParameter(candidateOne, candidateTwo));
        }