Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
        /// </summary>
        /// <param name="function">The Edm function, it should be bound function.</param>
        /// <param name="navigationSource">The Edm navigation source of this function return. It could be null.</param>
        /// <param name="requiredParameters">The required parameters of this function.</param>
        public FunctionSegmentTemplate(IEdmFunction function, IEdmNavigationSource navigationSource, ISet <string> requiredParameters)
        {
            Function = function ?? throw Error.ArgumentNull(nameof(function));

            NavigationSource = navigationSource;

            RequiredParameters = requiredParameters ?? throw Error.ArgumentNull(nameof(requiredParameters));

            // Only accept the bound function
            if (!function.IsBound)
            {
                throw new ODataException(string.Format(CultureInfo.CurrentCulture, SRResources.FunctionIsNotBound, function.Name));
            }

            // make sure the input parameter is subset of the function paremeters.
            ISet <string> functionParameters = function.GetFunctionParamters();

            if (!requiredParameters.IsSubsetOf(functionParameters))
            {
                string required = string.Join(",", requiredParameters);
                string actual   = string.Join(",", functionParameters);
                throw new ODataException(Error.Format(SRResources.RequiredParametersNotSubsetOfFunctionParameters, required, actual));
            }

            // Join the parameters as p1={p1}
            string parameters = "(" + string.Join(",", requiredParameters.Select(a => $"{a}={{{a}}}")) + ")";

            UnqualifiedIdentifier = function.Name + parameters;

            Literal = function.FullName() + parameters;

            // Function will always have the return type
            IsSingle = function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
 /// </summary>
 /// <param name="function">The Edm function, it should be bound function.</param>
 /// <param name="navigationSource">The Edm navigation source of this function return. It could be null.</param>
 public FunctionSegmentTemplate(IEdmFunction function, IEdmNavigationSource navigationSource)
     : this(function, navigationSource, function?.GetFunctionParamters())
 {
 }