Пример #1
0
 /// <summary>
 /// Convert name-value paris to URL query format.
 /// This overload handles <see cref="ExpandoObject"/> as well as anonymous objects.
 /// </summary>
 /// <remarks>
 /// <para>
 /// The key-value pair with null value will be excluded. To specify a key with empty value,
 /// consider using <see cref="string.Empty"/> .
 /// </para>
 /// <para>
 /// For <see cref="bool"/> values, if the value is true, a pair with key and empty value
 /// will be generated; otherwise the whole pair will be excluded.
 /// </para>
 /// <para>
 /// If <paramref name="values"/> is <see cref="IEnumerable{T}"/> of <see cref="KeyValuePair{TKey,TValue}"/>
 /// of strings, the values will be returned with no further processing.
 /// </para>
 /// </remarks>
 public static IEnumerable <KeyValuePair <string, string> > ToWikiStringValuePairs(object values)
 {
     if (values is IEnumerable <KeyValuePair <string, string> > pc)
     {
         return(pc);
     }
     return(MediaWikiHelper.EnumValues(values)
            .Select(p => new KeyValuePair <string, string>(p.Key, ToWikiQueryValue(p.Value))));
 }
 /// <inheritdoc />
 /// <param name="fieldCollection">A dictionary or anonymous object containing the key-value pairs. See <see cref="MediaWikiHelper.EnumValues"/> for more information.</param>
 /// <param name="forceMultipartFormData">Forces the message to be marshaled as multipart/form-data, regardless of the fields.</param>
 /// <exception cref="ArgumentNullException"><paramref name="fieldCollection"/> is <c>null</c>.</exception>
 public MediaWikiFormRequestMessage(string id, object fieldCollection, bool forceMultipartFormData) : base(id)
 {
     if (fieldCollection == null)
     {
         throw new ArgumentNullException(nameof(fieldCollection));
     }
     fields = new List <KeyValuePair <string, object> >(MediaWikiHelper.EnumValues(fieldCollection));
     AsMultipartFormData = forceMultipartFormData || fields.Any(p => p.Value is Stream);
 }
Пример #3
0
 /// <inheritdoc />
 /// <summary>
 /// Initializes a <see cref="WikiaQueryRequestMessage"/> instance with
 /// the message ID and query fields.
 /// </summary>
 /// <param name="fieldCollection">
 /// A dictionary or anonymous object containing the key-value pairs.
 /// See <see cref="MediaWikiHelper.EnumValues"/> for more information.
 /// For queries without query part, you can set this parameter to <c>null</c>.
 /// </param>
 /// <param name="httpPost">Whether to use HTTP POST method to issue the request.</param>
 public WikiaQueryRequestMessage(string id, object fieldCollection, bool httpPost) : base(id)
 {
     if (fieldCollection == null)
     {
         fields         = null;
         readonlyFields = Array.Empty <KeyValuePair <string, object> >();
     }
     else
     {
         fields = MediaWikiHelper.EnumValues(fieldCollection).ToList();
     }
     UseHttpPost = httpPost;
 }