Example #1
0
        private SqlNumber(SerializationInfo info)
        {
            state = info.GetValue <NumericState>("state");

            if (info.HasMember("byteCount"))
            {
                byteCount = info.GetInt32("byteCount");
            }
            else
            {
                byteCount = 120;
            }

            if (info.HasMember("valueAsLong"))
            {
                valueAsLong = info.GetInt64("valueAsLong");
                innerValue  = new BigDecimal(valueAsLong);
            }
            else if (state == NumericState.None)
            {
                valueAsLong = 0;

                var unscaledBytes = info.GetValue <byte[]>("unscaled");
                var scale         = info.GetInt32("scale");
                var precision     = info.GetInt32("precision");

                innerValue = new BigDecimal(new BigInteger(unscaledBytes), scale, new MathContext(precision));
            }
            else
            {
                innerValue  = null;
                valueAsLong = 0;
            }
        }
Example #2
0
        private SqlNumber(NumericState state, BigDecimal value)
            : this()
        {
            valueAsLong = 0;
            byteCount   = 120;

            if (value != null && value.Scale == 0)
            {
                BigInteger bint     = value.ToBigInteger();
                int        bitCount = bint.BitLength;
                if (bitCount < 30)
                {
                    valueAsLong = bint.ToInt64();
                    byteCount   = 4;
                }
                else if (bitCount < 60)
                {
                    valueAsLong = bint.ToInt64();
                    byteCount   = 8;
                }
            }

            innerValue = value;
            State      = state;
        }
Example #3
0
        private SqlNumber(SerializationInfo info, StreamingContext context)
        {
            var unscaledBytes = (byte[])info.GetValue("unscaled", typeof(byte[]));
            var precision     = info.GetInt32("precision");
            var scale         = info.GetInt32("scale");

            var value = new BigDecimal(new BigInteger(unscaledBytes), scale, new MathContext(precision));

            valueAsLong = 0;
            byteCount   = 120;

            if (value.Scale == 0)
            {
                var bint     = value.ToBigInteger();
                int bitCount = bint.BitLength;
                if (bitCount < 30)
                {
                    valueAsLong = bint.ToInt64();
                    byteCount   = 4;
                }
                else if (bitCount < 60)
                {
                    valueAsLong = bint.ToInt64();
                    byteCount   = 8;
                }
            }

            state      = (NumericState)info.GetByte("state");
            innerValue = value;
        }