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