/// <summary>
        /// Merge parameters from client and request
        /// </summary>
        /// <param name="client">The REST client that will execute the request</param>
        /// <param name="request">The REST request</param>
        /// <returns>A list of merged parameters</returns>
        public static IList <Parameter> MergeParameters([CanBeNull] this IRestClient client, IRestRequest request)
        {
            var parameters = new List <Parameter>();

            // Add default parameters first
            if (client != null)
            {
                parameters.AddRange(client.DefaultParameters);
            }

            // Now the client parameters
            if (request != null)
            {
                parameters.AddRange(request.Parameters);
            }

            var comparer = new ParameterComparer(client, request);

            var result = parameters
                         .Select((p, i) => new { Parameter = p, Index = i })

                         // Group by parameter type/name
                         .GroupBy(x => x.Parameter, comparer)

                         // Select only the last of all duplicate parameters
                         .Select(x => new { x.Last().Parameter, x.First().Index })

                         // Sort by appearance
                         .OrderBy(x => x.Index)
                         .Select(x => x.Parameter)
                         .ToList();

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Add overridable default parameters to the request
        /// </summary>
        /// <param name="request">The requests to add the default parameters to.</param>
        private void AddDefaultParameters(IRestRequest request)
        {
            var comparer = new ParameterComparer(this, request);

            var startIndex = 0;

            foreach (var parameter in DefaultParameters.Where(x => x.Type != ParameterType.HttpHeader))
            {
                if (request.Parameters.Contains(parameter, comparer))
                {
                    continue;
                }
                request.Parameters.Insert(startIndex++, parameter);
            }
        }