/// <summary> /// Determine the maximum lenght per value string. /// </summary> private int DetermineMaxLength <T>(CollectionParameterDefinition <T> collectionParameter, IEnumerable <ParameterDefinition> otherParameters) { // Add the empty collection to the parameter collection // to also count the characters of the parameter name and the collection delimiters. var emptyCollection = collectionParameter.Empty; // Determinde maximum length per value string var maxLength = RestClientHelper.GetUriTargetSize( _ServiceLocation, _RequestPath, _MaxUriLength, new[] { emptyCollection }.Concat(otherParameters).ToArray()); return(maxLength); }
/// <summary> /// Split the passed parameter collection into smaller chunks and merge each chunk with the rest of the parameters. /// </summary> /// <param name="collectionParameter">The collection parameter to split.</param> /// <param name="otherParameters">All other parameters that are part of the request, e.g. 'filter'.</param> /// <returns>A list of all parameter definitions for each chunk of the collection.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="collectionParameter"/> or <paramref name="otherParameters"/> is <see langword="null" />. /// </exception> public IEnumerable <IEnumerable <ParameterDefinition> > SplitAndMerge <T>( [NotNull] CollectionParameterDefinition <T> collectionParameter, [NotNull] IEnumerable <ParameterDefinition> otherParameters) { if (collectionParameter == null) { throw new ArgumentNullException(nameof(collectionParameter)); } if (otherParameters == null) { throw new ArgumentNullException(nameof(otherParameters)); } var otherParametersArray = otherParameters.ToArray(); var maxLength = DetermineMaxLength(collectionParameter, otherParametersArray); var splitParameters = collectionParameter.Split(maxLength); return(MergeWithOtherParameters(splitParameters, otherParametersArray)); }