private void Import(byte[] io) { CheckReadOnly(); if (Blob?.Any() != true) { return; } if (io != null) { for (int i = 0, ix = 0, len = Blob.Length; ix < len; ix++) { if (i >= io.Length) { Blob[ix] = 0; } else if (i + sizeof(ulong) < io.Length) { Blob[ix] = IOEx.GetUInt64(io, ref i, false); } else { byte[] b = new byte[sizeof(ulong)]; Array.Copy(io, i, b, 0, io.Length - i); int ii = 0; Blob[ix] = IOEx.GetUInt64(b, ref ii, false); i = io.Length; } } } else { Blob.Fill(0UL); } }
public static ulong?GetULong(object val, bool parse) { if (val == null) { return(null); } try { TypeCode tc = val.GetTypeCode(); switch (tc) { case TypeCode.String: if (!parse) { return(null); } ulong n; if (!TryFromServer(Convert.ToString(val), out n, 0)) { return(null); } return(n); case TypeCode.Int64: return(unchecked ((ulong)(long)val)); default: if (IsNumeric(tc)) { return(Convert.ToUInt64(val)); } byte[] b = val as byte[]; int ix = 0; if (b?.Length == sizeof(ulong)) { return(IOEx.GetUInt64(b, ref ix)); } return(null); } } catch { return(null); } }