示例#1
0
        /// <summary>
        /// Finds all signatures for the given function name.
        /// Search in both BuiltIn uri functions and Custom uri functions.
        /// Combine and return the signatures overloads of the results.
        /// </summary>
        /// <param name="functionName">The function to get the signatures for.</param>
        /// <returns>The signatures which match the supplied function name.</returns>
        internal static FunctionSignatureWithReturnType[] GetUriFunctionSignatures(string functionName)
        {
            FunctionSignatureWithReturnType[] customUriFunctionsSignatures  = null;
            FunctionSignatureWithReturnType[] builtInUriFunctionsSignatures = null;

            // Try to find the function in the user custom functions and in our built-in functions
            bool customFound  = CustomUriFunctions.TryGetCustomFunction(functionName, out customUriFunctionsSignatures);
            bool builtInFound = BuiltInUriFunctions.TryGetBuiltInFunction(functionName, out builtInUriFunctionsSignatures);

            if (!customFound && !builtInFound)
            {
                // Not found in both built-in and custom.
                throw new ODataException(ODataErrorStrings.MetadataBinder_UnknownFunction(functionName));
            }

            if (!customFound)
            {
                Debug.Assert(builtInUriFunctionsSignatures != null, "No Built-in functions found");
                return(builtInUriFunctionsSignatures);
            }

            if (!builtInFound)
            {
                Debug.Assert(customUriFunctionsSignatures != null, "No Custom functions found");
                return(customUriFunctionsSignatures);
            }

            return(builtInUriFunctionsSignatures.Concat(customUriFunctionsSignatures).ToArray());
        }
示例#2
0
        internal static IList <KeyValuePair <string, FunctionSignatureWithReturnType> > GetUriFunctionSignatures(string functionCallToken, bool enableCaseInsensitive = false)
        {
            IList <KeyValuePair <string, FunctionSignatureWithReturnType> > customUriFunctionsNameSignatures = null;

            FunctionSignatureWithReturnType[] builtInUriFunctionsSignatures = null;
            IList <KeyValuePair <string, FunctionSignatureWithReturnType> > builtInUriFunctionsNameSignatures = null;

            // Try to find the function in the user custom functions
            bool customFound = CustomUriFunctions.TryGetCustomFunction(functionCallToken, out customUriFunctionsNameSignatures,
                                                                       enableCaseInsensitive);

            // And find in our built-in functions
            // Since list of all built-in functions is a fixed list and is initialized with names in lower case,
            // such as "endswith", "geo.distance", "maxdatetime" and "round",
            // => For case-insensitive searching, it is more efficient to convert the search key to lower case first
            //    and then do a case-sensitive match.
            string nameKey = enableCaseInsensitive
                ? functionCallToken.ToLowerInvariant()
                : functionCallToken;
            bool builtInFound = BuiltInUriFunctions.TryGetBuiltInFunction(nameKey, out builtInUriFunctionsSignatures);

            // Populate the matched names found for built-in function
            if (builtInFound)
            {
                builtInUriFunctionsNameSignatures =
                    builtInUriFunctionsSignatures.Select(sig => new KeyValuePair <string, FunctionSignatureWithReturnType>(nameKey, sig)).ToList();
            }

            if (!customFound && !builtInFound)
            {
                // Not found in both built-in and custom.
                throw new ODataException(ODataErrorStrings.MetadataBinder_UnknownFunction(functionCallToken));
            }

            if (!customFound)
            {
                Debug.Assert(builtInUriFunctionsNameSignatures != null, "No Built-in functions found");
                return(builtInUriFunctionsNameSignatures);
            }

            if (!builtInFound)
            {
                Debug.Assert(customUriFunctionsNameSignatures != null, "No Custom functions found");
                return(customUriFunctionsNameSignatures);
            }

            return(builtInUriFunctionsNameSignatures.Concat(customUriFunctionsNameSignatures).ToArray());
        }