public static bool TryReadQueryAs(this Uri address, Type type, out object value) { if (address == null) { throw new ArgumentNullException("address"); } if (type == null) { throw new ArgumentNullException("type"); } IEnumerable <KeyValuePair <string, string> > query = new FormDataCollection(address); JObject jsonObject; if (FormUrlEncodedJson.TryParse(query, out jsonObject)) { using (JTokenReader jsonReader = new JTokenReader(jsonObject)) { value = new JsonSerializer().Deserialize(jsonReader, type); } return(true); } value = null; return(false); }
/// <summary> /// Reads HTML form URL encoded data provided in the <see cref="Uri"/> query component as a <see cref="JObject"/> object. /// </summary> /// <param name="address">The <see cref="Uri"/> instance from which to read.</param> /// <param name="value">An object to be initialized with this instance or null if the conversion cannot be performed.</param> /// <returns><c>true</c> if the query component can be read as <see cref="JObject"/>; otherwise <c>false</c>.</returns> public static bool TryReadQueryAsJson(this Uri address, out JObject value) { if (address == null) { throw new ArgumentNullException("address"); } IEnumerable <KeyValuePair <string, string> > query = new FormDataCollection(address); return(FormUrlEncodedJson.TryParse(query, out value)); }
public static bool TryReadQueryAs <T>(this Uri address, out T value) { if (address == null) { throw new ArgumentNullException("address"); } IEnumerable <KeyValuePair <string, string> > query = new FormDataCollection(address); JObject jsonObject; if (FormUrlEncodedJson.TryParse(query, out jsonObject)) { value = jsonObject.ToObject <T>(); return(true); } value = default(T); return(false); }