/// <summary> /// Bind a select and expand option. /// </summary> /// <param name="syntax">A syntax tree containing the select and expand options to bind</param> /// <param name="path">the top level path</param> /// <param name="configuration">The configuration to use for binding.</param> /// <returns>a select expand clause bound to metadata</returns> public static SelectExpandClause BindSelectExpand(SyntacticTree syntax, ODataPath path, ODataUriParserConfiguration configuration) { if (syntax.Select != null || syntax.Expand != null) { if (!path.EdmType().IsEntityCollection() && !path.EdmType().IsEntity()) { throw new ODataException(ODataErrorStrings.MetadataBinder_QueryOptionNotApplicable("$select or $expand")); } return(SelectExpandSemanticBinder.Parse((IEdmEntityType)((IEdmCollectionTypeReference)path.EdmType()).ElementType().Definition, path.EntitySet(), syntax.Expand, syntax.Select, configuration)); } return(null); }
/// <summary> /// Constructs a <see cref="BindingState"/> with the given <paramref name="configuration"/>. /// </summary> /// <param name="configuration">The configuration used for binding.</param> internal BindingState(ODataUriParserConfiguration configuration) { DebugUtils.CheckNoExternalCallers(); ExceptionUtils.CheckArgumentNotNull(configuration, "configuration"); this.configuration = configuration; }
/// <summary> /// Build an ODataUriParser /// </summary> /// <param name="model">Model to use for metadata binding.</param> /// <param name="serviceRoot">Absolute URI of the service root.</param> /// <exception cref="System.ArgumentNullException">Throws if input model is null.</exception> /// <exception cref="ArgumentException">Throws if the input serviceRoot is not an AbsoluteUri</exception> public ODataUriParser(IEdmModel model, Uri serviceRoot) { this.configuration = new ODataUriParserConfiguration(model, serviceRoot); }
/// <summary> /// Tries to parse a collection of function parameters for path. /// </summary> /// <param name="splitParameters">The split parameters from the syntactic parsing step.</param> /// <param name="configuration">The configuration for the URI Parser.</param> /// <param name="functionImport">The function import for the function whose parameters are being parsed.</param> /// <param name="parsedParameters">The parameters if they were successfully parsed.</param> /// <returns>Whether the parameters could be parsed.</returns> internal static bool TryParseFunctionParameters(ICollection <FunctionParameterToken> splitParameters, ODataUriParserConfiguration configuration, IEdmFunctionImport functionImport, out ICollection <OperationSegmentParameter> parsedParameters) { DebugUtils.CheckNoExternalCallers(); return(TryParseFunctionParameters(splitParameters, configuration, functionImport, (paramName, convertedValue) => new OperationSegmentParameter(paramName, convertedValue), out parsedParameters)); }
/// <summary> /// Tries to create a parameter using any representation based on the provided delegate for creating it from a converted value. /// </summary> /// <typeparam name="TParam">The type used to represent a parameter.</typeparam> /// <param name="parameterToken">The token from the syntactic parsing step.</param> /// <param name="configuration">The configuration for the URI Parser.</param> /// <param name="expectedType">The type that the parameter is expected to resolve to.</param> /// <param name="createParameter">Callback to create the final parameter from the parsed value.</param> /// <param name="parameter">The parameter if one was successfully created.</param> /// <returns>Whether the parameter could be created from the parameterToken.</returns> private static bool TryCreateParameter <TParam>(FunctionParameterToken parameterToken, ODataUriParserConfiguration configuration, IEdmTypeReference expectedType, Func <object, TParam> createParameter, out TParam parameter) { Debug.Assert(parameterToken != null, "parameterToken != null"); QueryToken valueToken = parameterToken.ValueToken; object convertedValue; if (valueToken.Kind == QueryTokenKind.FunctionParameterAlias && configuration.FunctionParameterAliasCallback == null) { convertedValue = new ODataUnresolvedFunctionParameterAlias(((FunctionParameterAliasToken)valueToken).Alias, expectedType); } else { string textToParse; if (valueToken.Kind == QueryTokenKind.FunctionParameterAlias) { textToParse = configuration.FunctionParameterAliasCallback(((FunctionParameterAliasToken)valueToken).Alias); } else if (valueToken.Kind == QueryTokenKind.RawFunctionParameterValue) { textToParse = ((RawFunctionParameterValueToken)valueToken).RawText; } else { parameter = default(TParam); return(false); } if (textToParse == null) { convertedValue = null; } else { convertedValue = ODataUriUtils.ConvertFromUriLiteral(textToParse, ODataVersion.V3, configuration.Model, expectedType); } } parameter = createParameter(convertedValue); return(true); }
private static bool TryParseFunctionParameters <TParam>(ICollection <FunctionParameterToken> splitParameters, ODataUriParserConfiguration configuration, IEdmFunctionImport functionImport, Func <string, object, TParam> createParameter, out ICollection <TParam> parsedParameters) { Debug.Assert(splitParameters != null, "splitParameters != null"); Debug.Assert(createParameter != null, "createParameter != null"); Debug.Assert(configuration != null, "configuration != null"); Debug.Assert(functionImport != null, "functionImport != null"); parsedParameters = new List <TParam>(splitParameters.Count); foreach (var splitParameter in splitParameters) { TParam parameter; IEdmTypeReference expectedType = null; IEdmFunctionParameter edmFunctionParameter = null; try { edmFunctionParameter = functionImport.FindParameter(splitParameter.ParameterName); } catch (InvalidOperationException ex) { // this can throw an exception if there are multiple parameters with the same name.. // catch that exception and throw something more sane. throw new ODataException(ODataErrorStrings.FunctionCallParser_DuplicateParameterName, ex); } Debug.Assert(edmFunctionParameter != null, "At this point we should know that the parameter names match the given function import."); expectedType = edmFunctionParameter.Type; if (!TryCreateParameter(splitParameter, configuration, expectedType, o => createParameter(splitParameter.ParameterName, o), out parameter)) { return(false); } parsedParameters.Add(parameter); } return(true); }