private SqlDateTime ToDate(ISqlBinary binary)
        {
            if (binary == null)
            {
                throw new InvalidCastException();
            }

            var bytes = binary.ToArray();

            return(new SqlDateTime(bytes));
        }
        private ISqlValue ToString(ISqlBinary binary, SqlCharacterType destType)
        {
            if (binary == null)
            {
                throw new InvalidCastException();
            }

            var bytes = binary.ToArray();
            var s     = new SqlString(bytes);

            return(destType.NormalizeValue(s));
        }
        private ISqlValue ToNumber(ISqlBinary value, SqlNumericType destType)
        {
            if (value == null)
            {
                throw new InvalidCastException();
            }

            var precision = destType.Precision;
            var scale     = destType.Scale;

            if (precision <= 0)
            {
                throw new NotSupportedException();
            }
            if (scale <= 0)
            {
                scale = 1;
            }

            // TODO: handle the cases when precision and/or scale are not set
            return(new SqlNumber(value.ToArray(), scale, precision));
        }