Monday, November 22, 2010

You can’t handle the Boolean truths

I see your Boolean Truths, and I raise you a ParamValueIsTrueAsBoolean.

protected bool ParamValueIsTrueAsBoolean(string stringvalue)
{
    return (stringvalue.Equals("J") ||
        stringvalue.Equals("Y") ||
        stringvalue.Equals("1") ||
        stringvalue.Equals("j") ||
        stringvalue.Equals("y") ||
        stringvalue.Equals("True") ||
        stringvalue.Equals("true"));
}

2 comments:

  1. It's always bothered me that "V" and "v" are missing from that list - we're a bilingual country, so how can was skip vrai?

    ReplyDelete
  2. Sadder still, this code came from a trilingual country. Although, it was from the side that hates the French.

    ReplyDelete