コード例 #1
0
        public OverloadResolutionData<T> IsApplicableFunctionMember<T>(FunctionMemberData<T> functionMember, IImmutableList<Type> argumentList)
            where T : MemberInfo
        {
            var parameters = functionMember.Parameters;
            var lastParam = parameters.LastOrDefault();
            var hasParamsArray = functionMember.HasParamsArray;

            int fixedParams = hasParamsArray
                ? parameters.Length - 1
                : parameters.Length;

            if (!hasParamsArray && argumentList.Count != fixedParams)
                return null;
            else if (argumentList.Count < fixedParams)
                return null;

            // Each argument in A corresponds to a parameter in the function member declaration
            for (int i = 0; i < fixedParams; i++)
            {
                if (!_argumentConverter.CanBeConverted(argumentList[i], parameters[i]))
                    return null;
            }

            ApplicableForm applicableForm;
            if (!hasParamsArray)
            {
                applicableForm = ApplicableForm.Normal;
            }
            // For a function member that includes a parameter array, if the function member is applicable by the above rules, it is said to be applicable in its normal form.
            else if (argumentList.Count == parameters.Length && _argumentConverter.CanBeConverted(argumentList[fixedParams], parameters[fixedParams]))
            {
                applicableForm = ApplicableForm.Normal;

            }
            // If a function member that includes a parameter array is not applicable in its normal form, the function member may instead be applicable in its expanded form
            else
            {
                var paramArrayElementType = lastParam.GetElementType();
                for (int i = fixedParams; i < argumentList.Count; i++)
                {
                    if (!_argumentConverter.CanBeConverted(argumentList[i], paramArrayElementType))
                        return null;
                }

                applicableForm = ApplicableForm.Expanded;
            }

            return new OverloadResolutionData<T>(applicableForm, functionMember);
        }
コード例 #2
0
 public OverloadResolutionData(ApplicableForm applicableForm, FunctionMemberData <T> functionMember)
 {
     ApplicableForm = applicableForm;
     FunctionMember = functionMember.FunctionMember;
     Parameters     = functionMember.Parameters;
 }