BetterMembership.Extensions.NameValueCollectionExtension.GetBoolean C# (CSharp) Method

GetBoolean() public static method

public static GetBoolean ( this collection, string key, bool defaultValue = false ) : bool
collection this
key string
defaultValue bool
return bool
        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;
        }