Пример #1
0
 public void ToInt16FromBigEndian()
 {
     Assert.AreEqual(0, SqlBitConverter.ToInt16FromBigEndian(new byte[] { 0x0 }, 0, Offset.Zero));
     Assert.AreEqual(239, SqlBitConverter.ToInt16FromBigEndian(new byte[] { 0xEF }, 0, Offset.Zero));
     Assert.AreEqual(111, SqlBitConverter.ToInt16FromBigEndian(new byte[] { 0xEF }, 0, Offset.MinValue));
     Assert.AreEqual(-112, SqlBitConverter.ToInt16FromBigEndian(new byte[] { 0x10 }, 0, Offset.MinValue));
     Assert.AreEqual(20239, SqlBitConverter.ToInt16FromBigEndian(new byte[] { 0x4F, 0x0F }, 0, Offset.Zero));
 }
Пример #2
0
        public override object GetValue(byte[] value)
        {
            if (CompressionContext.CompressionLevel != CompressionLevel.None)
            {
                if (value.Length > 2)
                {
                    throw new ArgumentException("Invalid value length: " + value.Length);
                }

                return(SqlBitConverter.ToInt16FromBigEndian(value, 0, Offset.MinValue));
            }
            else
            {
                if (value.Length != 2)
                {
                    throw new ArgumentException("Invalid value length: " + value.Length);
                }

                return(BitConverter.ToInt16(value, 0));
            }
        }