public static byte?GetByte(object val, bool parse) { if (val == null) { return(null); } try { TypeCode tc = val.GetTypeCode(); switch (tc) { case TypeCode.String: if (!parse) { return(null); } byte n; if (!TryFromServer(Convert.ToString(val), out n, 0)) { return(null); } return(n); case TypeCode.SByte: return(unchecked ((byte)(sbyte)val)); default: if (IsNumeric(tc)) { return(Convert.ToByte(val)); } byte[] b = val as byte[]; int ix = 0; if (b?.Length == sizeof(byte)) { return(IOEx.GetByte(b, ref ix)); } return(null); } } catch { return(null); } }