Exemplo n.º 1
0
        /// <summary>
        /// Serializes the value of a query parameter, using an appropriate method
        /// </summary>
        /// <param name="queryParameter">Query parameter to serialize</param>
        /// <param name="requestInfo">RequestInfo representing the request</param>
        /// <returns>Serialized value</returns>
        protected virtual IEnumerable <KeyValuePair <string, string> > SerializeQueryParameter(QueryParameterInfo queryParameter, IRequestInfo requestInfo)
        {
            switch (queryParameter.SerializationMethod)
            {
            case QuerySerializationMethod.ToString:
                return(queryParameter.SerializeToString(this.FormatProvider));

            case QuerySerializationMethod.Serialized:
                if (this.RequestQueryParamSerializer == null)
                {
                    throw new InvalidOperationException("Cannot serialize query parameter when RequestQueryParamSerializer is null. Please set RequestQueryParamSerializer");
                }
                var result = queryParameter.SerializeValue(this.RequestQueryParamSerializer, requestInfo, this.FormatProvider);
                return(result ?? Enumerable.Empty <KeyValuePair <string, string> >());

            default:
                throw new InvalidOperationException("Should never get here");
            }
        }