ThisToThat/ThisToThat/ToBooleanExtensions.cs
/// <summary>
/// Converts and returns this string's value as a boolean or the specified default value.
/// Values which will convert to true are: "TRUE", "T", "YES", "Y", "ON", "1"
/// Values which will convert to false are: "FALSE", "F", "NO", "N", "OFF", "0"
/// All other values will convert to the default specified.
/// </summary>
Converts and returns this string's value as a boolean or the specified default value.
Converts and returns this string ' s value as a boolean or the specified default value .
public static bool ToBooleanOrDefault(this string thisString, bool defaultValue = default(bool))
        {
            bool returnValue = defaultValue;
            if (_TRUE_STRINGS.Contains(thisString.ToUpper()))
                returnValue = true;
            else if (_FALSE_STRINGS.Contains(thisString.ToUpper()))
                returnValue = false;
            return returnValue;
        }
public static bool ToBooleanOrDefault ( this string thisString , bool defaultValue = default ( bool ) ) { bool returnValue = defaultValue ; if ( _TRUE_STRINGS . Contains ( thisString . ToUpper ( ) ) ) returnValue = true ; else if ( _FALSE_STRINGS . Contains ( thisString . ToUpper ( ) ) ) returnValue = false ; return returnValue ; }
Converts and returns this string's value as a boolean or the specified default value.
Converts and returns this string ' s value as a boolean or the specified default value .
string
this
defaultValue
bool