public static bool GetBoolean(this NameValueCollection collection, string key, bool defaultValue = false)
{
Condition.Requires(key, "key").IsNotNullOrWhiteSpace();
if (collection == null)
{
return defaultValue;
}
var value = collection.GetString(key);
if (string.IsNullOrWhiteSpace(value))
{
return defaultValue;
}
bool returnValue;
return bool.TryParse(value, out returnValue) ? returnValue : defaultValue;
}