public static bool?GetBool(object val, bool parse) { if (val == null) { return(null); } try { TypeCode tc = val.GetTypeCode(); switch (tc) { case TypeCode.String: if (!parse) { return(null); } bool n; string s = StringEx.UserText(val as string); if (s == null) { return(null); } if (TryFromServer(s, out n, false)) { return(n); } switch (s[0]) { case 'T': case 't': case '1': return(true); case 'F': case 'f': case '0': return(false); default: return(null); } default: if (IsNumeric(tc)) { return(Convert.ToBoolean(val)); } byte[] b = val as byte[]; int ix = 0; if (b?.Length == sizeof(bool)) { return(IOEx.GetBool(b, ref ix)); } return(null); } } catch { return(null); } }