/// <summary> /// Gets the value of the request. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="httpRequest">The HTTP request.</param> /// <param name="key">The key.</param> /// <param name="defaultValue">The default value.</param> /// <returns></returns> public static T Get <T>(this HttpRequestBase httpRequest, string key, T defaultValue) { if (httpRequest.ContainsKey(key) == false) { return(defaultValue); } string value = httpRequest[key]; if (string.IsNullOrWhiteSpace(value)) { return(defaultValue); } // http://www.hanselman.com/blog/TypeConvertersTheresNotEnoughTypeDescripterGetConverterInTheWorld.aspx TypeConverter converter = TypeDescriptor.GetConverter(typeof(T)); return((T)(converter.ConvertFromInvariantString(value))); }