Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionImportSegmentTemplate" /> class.
        /// </summary>
        /// <param name="segment">The input function import segment.</param>
        public FunctionImportSegmentTemplate(OperationImportSegment segment)
        {
            if (segment == null)
            {
                throw Error.ArgumentNull(nameof(segment));
            }

            IEdmOperationImport operationImport = segment.OperationImports.First();

            if (!operationImport.IsFunctionImport())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "FunctionImport", "FunctionImportSegmentTemplate"));
            }

            FunctionImport = (IEdmFunctionImport)operationImport;

            NavigationSource = segment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(segment.Parameters, operationImport.Name);

            // join the parameters as p1={p1}
            Literal = FunctionImport.Name + "(" + string.Join(",", ParameterMappings.Select(a => $"{a.Key}={{{a.Value}}}")) + ")";

            IsSingle = FunctionImport.Function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
        /// </summary>
        /// <param name="operationSegment">The operation segment, it should be a function segment and the parameters are template.</param>
        public FunctionSegmentTemplate(OperationSegment operationSegment)
        {
            if (operationSegment == null)
            {
                throw Error.ArgumentNull(nameof(operationSegment));
            }

            IEdmOperation operation = operationSegment.Operations.FirstOrDefault();

            if (!operation.IsFunction())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "Function", "FunctionSegmentTemplate"));
            }

            Function = (IEdmFunction)operation;

            NavigationSource = operationSegment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(operationSegment.Parameters, operation.FullName());

            // join the parameters as p1={p1}
            string routeKey = ParameterMappings.BuildRouteKey();

            string parameterStr = ParameterMappings.Count == 0 ? "()" : $"({{{routeKey}}})";

            UnqualifiedIdentifier = Function.Name + parameterStr;

            Literal = Function.FullName() + parameterStr;

            // Function will always have the return type
            IsSingle = Function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionImportSegmentTemplate" /> class.
        /// </summary>
        /// <param name="segment">The input function import segment.</param>
        public FunctionImportSegmentTemplate(OperationImportSegment segment)
        {
            if (segment == null)
            {
                throw Error.ArgumentNull(nameof(segment));
            }

            IEdmOperationImport operationImport = segment.OperationImports.First();

            if (!operationImport.IsFunctionImport())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "FunctionImport", "FunctionImportSegmentTemplate"));
            }

            FunctionImport = (IEdmFunctionImport)operationImport;

            NavigationSource = segment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(segment.Parameters, operationImport.Name);

            // join the parameters as p1={p1}
            string routeKey     = ParameterMappings.BuildRouteKey();
            string parameterStr = ParameterMappings.Count == 0 ? "()" : $"({{{routeKey}}})";

            Literal = FunctionImport.Name + parameterStr;

            IsSingle = FunctionImport.Function.ReturnType.TypeKind() != EdmTypeKind.Collection;
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
        /// </summary>
        /// <param name="operationSegment">The operation segment, it should be a function segment and the parameters are template.</param>
        public FunctionSegmentTemplate(OperationSegment operationSegment)
        {
            if (operationSegment == null)
            {
                throw Error.ArgumentNull(nameof(operationSegment));
            }

            IEdmOperation operation = operationSegment.Operations.FirstOrDefault();

            if (!operation.IsFunction())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "Function", "FunctionSegmentTemplate"));
            }

            Function = (IEdmFunction)operation;

            NavigationSource = operationSegment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(operationSegment.Parameters, operation.FullName());

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

            UnqualifiedIdentifier = Function.Name + parameterStr;

            Literal = Function.FullName() + parameterStr;

            // Function will always have the return type
            IsSingle = Function.ReturnType.TypeKind() != EdmTypeKind.Collection;

            HasOptionalMissing = ParameterMappings.Count != Function.Parameters.Count() - 1;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class.
        /// </summary>
        /// <param name="operationSegment">The operation segment, it should be a function segment and the parameters are template.</param>
        public FunctionSegmentTemplate(OperationSegment operationSegment)
        {
            if (operationSegment == null)
            {
                throw Error.ArgumentNull(nameof(operationSegment));
            }

            IEdmOperation operation = operationSegment.Operations.FirstOrDefault();

            if (!operation.IsFunction())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "Function", "FunctionSegmentTemplate"));
            }

            Function = (IEdmFunction)operation;

            NavigationSource = operationSegment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(operationSegment.Parameters, operation.FullName());
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FunctionImportSegmentTemplate" /> class.
        /// </summary>
        /// <param name="segment">The input function import segment.</param>
        public FunctionImportSegmentTemplate(OperationImportSegment segment)
        {
            if (segment == null)
            {
                throw Error.ArgumentNull(nameof(segment));
            }

            IEdmOperationImport operationImport = segment.OperationImports.First();

            if (!operationImport.IsFunctionImport())
            {
                throw new ODataException(Error.Format(SRResources.SegmentShouldBeKind, "FunctionImport", "FunctionImportSegmentTemplate"));
            }

            FunctionImport = (IEdmFunctionImport)operationImport;

            NavigationSource = segment.EntitySet;

            ParameterMappings = OperationHelper.BuildParameterMappings(segment.Parameters, operationImport.Name);
        }