Exemplo n.º 1
0
        /// <summary>
        /// Bind this function call token as a built in function
        /// </summary>
        /// <param name="functionCallToken">the function call token to bidn</param>
        /// <param name="argumentNodes">list of semantically bound arguments</param>
        /// <returns>A function call node bound to this function.</returns>
        private QueryNode BindAsBuiltInFunction(FunctionCallToken functionCallToken, List <QueryNode> argumentNodes)
        {
            if (functionCallToken.Source != null)
            {
                // the parent must be null for a built in function.
                throw new ODataException(ODataErrorStrings.FunctionCallBinder_BuiltInFunctionMustHaveHaveNullParent(functionCallToken.Name));
            }

            string functionCallTokenName = this.state.Configuration.EnableCaseInsensitiveBuiltinIdentifier ? functionCallToken.Name.ToLowerInvariant() : functionCallToken.Name;

            // There are some functions (IsOf and Cast for example) that don't necessarily need to be bound to a BuiltInFunctionSignature,
            // for these, we just Bind them directly to a SingleValueFunctionCallNode
            if (IsUnboundFunction(functionCallTokenName))
            {
                return(CreateUnboundFunctionNode(functionCallTokenName, argumentNodes));
            }

            // Do some validation and get potential built-in functions that could match what we saw
            FunctionSignatureWithReturnType[] signatures = GetBuiltInFunctionSignatures(functionCallTokenName);
            SingleValueNode[] argumentNodeArray          = ValidateArgumentsAreSingleValue(functionCallTokenName, argumentNodes);
            FunctionSignatureWithReturnType signature    = MatchSignatureToBuiltInFunction(functionCallTokenName, argumentNodeArray, signatures);

            if (signature.ReturnType != null)
            {
                TypePromoteArguments(signature, argumentNodes);
            }

            IEdmTypeReference returnType = signature.ReturnType;

            return(new SingleValueFunctionCallNode(functionCallTokenName, new ReadOnlyCollection <QueryNode>(argumentNodes), returnType));
        }