Пример #1
0
        /// <summary>Implements the visitor pattern for the function.</summary>
        /// <returns>The implemented visitor pattern.</returns>
        /// <param name="functionMetadata">The function metadata.</param>
        protected override EdmFunction VisitFunction(EdmFunction functionMetadata)
        {
            var paramTypes = new List <TypeUsage>(functionMetadata.Parameters.Count);

            foreach (var funcParam in functionMetadata.Parameters)
            {
                var mappedParamType = VisitTypeUsage(funcParam.TypeUsage);
                paramTypes.Add(mappedParamType);
            }

            if (DataSpace.SSpace
                == functionMetadata.DataSpace)
            {
                EdmFunction foundFunc = null;
                if (_metadata.TryGetFunction(
                        functionMetadata.Name,
                        functionMetadata.NamespaceName,
                        paramTypes.ToArray(),
                        false /* ignoreCase */,
                        functionMetadata.DataSpace,
                        out foundFunc)
                    &&
                    foundFunc != null)
                {
                    return(foundFunc);
                }
            }
            else
            {
                // Find the function or function import.
                IList <EdmFunction> candidateFunctions;
                if (_perspective.TryGetFunctionByName(
                        functionMetadata.NamespaceName, functionMetadata.Name, /*ignoreCase:*/ false, out candidateFunctions))
                {
                    Debug.Assert(
                        null != candidateFunctions && candidateFunctions.Count > 0,
                        "Perspective.TryGetFunctionByName returned true with null/empty function result list");

                    bool isAmbiguous;
                    var  retFunc = FunctionOverloadResolver.ResolveFunctionOverloads(
                        candidateFunctions, paramTypes, /*isGroupAggregateFunction:*/ false, out isAmbiguous);
                    if (!isAmbiguous
                        &&
                        retFunc != null)
                    {
                        return(retFunc);
                    }
                }
            }

            throw new ArgumentException(
                      Strings.Cqt_Copier_FunctionNotFound(TypeHelpers.GetFullName(functionMetadata.NamespaceName, functionMetadata.Name)));
        }