/// <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; }
/// <summary> /// Initializes a new instance of the <see cref="FunctionSegmentTemplate" /> class. /// </summary> /// <param name="parameters">The function parameter template mappings.The key string is case-sensitive, the value string should wrapper with { and }.</param> /// <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(IDictionary <string, string> parameters, IEdmFunction function, IEdmNavigationSource navigationSource) { if (parameters == null) { throw Error.ArgumentNull(nameof(parameters)); } Function = function ?? throw Error.ArgumentNull(nameof(function)); NavigationSource = navigationSource; // Only accept the bound function if (!function.IsBound) { throw new ODataException(Error.Format(SRResources.FunctionIsNotBound, function.Name)); } // Parameters should include all required parameter, but maybe include the optional parameter. ParameterMappings = function.VerifyAndBuildParameterMappings(parameters); 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="parameters">The function parameter template mappings.The key string is case-sensitive, the value string should wrapper with { and }.</param> /// <param name="functionImport">The Edm function import.</param> /// <param name="navigationSource">The target navigation source, it could be null.</param> public FunctionImportSegmentTemplate(IDictionary <string, string> parameters, IEdmFunctionImport functionImport, IEdmNavigationSource navigationSource) { if (parameters == null) { throw Error.ArgumentNull(nameof(parameters)); } FunctionImport = functionImport ?? throw Error.ArgumentNull(nameof(functionImport)); NavigationSource = navigationSource; // parameters should include all required parameter, but maybe include the optional parameter. ParameterMappings = functionImport.Function.VerifyAndBuildParameterMappings(parameters); string routeKey = ParameterMappings.BuildRouteKey(); string parameterStr = ParameterMappings.Count == 0 ? "()" : $"({{{routeKey}}})"; Literal = functionImport.Name + parameterStr; IsSingle = functionImport.Function.ReturnType.TypeKind() != EdmTypeKind.Collection; }