Ejemplo n.º 1
0
        internal static IEdmFunctionImport ResolveOverloadsByParameterNames(ICollection <IEdmFunctionImport> functionImports, ICollection <string> parameters, string functionName)
        {
            DebugUtils.CheckNoExternalCallers();
            IEdmFunctionImport candidateFunction = null;

            foreach (IEdmFunctionImport functionImport in functionImports)
            {
                IEnumerable <IEdmFunctionParameter> parametersToMatch = functionImport.Parameters;

                // bindable functions don't require the first parameter be specified, since its already implied in the path.
                if (functionImport.IsBindable)
                {
                    parametersToMatch = parametersToMatch.Skip(1);
                }

                // if any parameter count is different, don't consider it a match.
                List <IEdmFunctionParameter> functionImportParameters = parametersToMatch.ToList();
                if (functionImportParameters.Count != parameters.Count)
                {
                    continue;
                }

                // if any parameter was missing, don't consider it a match.
                if (functionImportParameters.Any(p => parameters.All(k => k != p.Name)))
                {
                    continue;
                }

                if (candidateFunction == null)
                {
                    candidateFunction = functionImport;
                }
                else
                {
                    throw new ODataException(ODataErrorStrings.FunctionOverloadResolver_NoSingleMatchFound(functionName, string.Join(", ", parameters.ToArray())));
                }
            }

            return(candidateFunction);
        }