Exemplo n.º 1
0
        private Boolean ReadValues(System.IO.BinaryReader r)
        {
            Int32 count;
              if(r.BaseStream.Length == 0) return false;
              count = Sql.Read7BitEncodedInt(r);

              if (count == 0) return true;

              for (Int32 i = 0; i < count; i++)
              {
            String    name  = r.ReadString();
            SqlDbType LType = (SqlDbType)r.ReadUInt16();
            Object    value = null;
            Int32 len;
            //Int32 lcid;
            //SqlCompareOptions co;

            switch (LType)
            {
              case SqlDbType.Bit      : value = new SqlBoolean(r.ReadBoolean()); break;
              case SqlDbType.TinyInt  : value = new SqlByte(r.ReadByte()); break;
              case SqlDbType.SmallInt : value = new SqlInt16((Int16)r.ReadInt16()); break;
              case SqlDbType.Int      : value = new SqlInt32((Int32)r.ReadInt32()); break;
              case SqlDbType.BigInt   : value = new SqlInt64(r.ReadInt64()); break;

              case SqlDbType.Binary   :
              case SqlDbType.VarBinary: len = r.ReadUInt16(); value = new SqlBytes(r.ReadBytes(len)); break;

              case SqlDbType.Char     :
              case SqlDbType.VarChar  : //value = new Sql.SqlAnsiString(r); break;
              case SqlDbType.NChar:
              case SqlDbType.NVarChar:
            //co = (SqlCompareOptions)r.ReadUInt16();
            //lcid = r.ReadInt32();
            //value = new SqlString(r.ReadString(), lcid, co);
            value = new SqlString(r.ReadString());
            break;

              case SqlDbType.DateTime     : value = new SqlDateTime(DateTime.FromBinary(r.ReadInt64())); break;
              case SqlDbType.SmallDateTime:
              case SqlDbType.Date         :
              case SqlDbType.DateTime2    : value = DateTime.FromBinary(r.ReadInt64()); break;
              case SqlDbType.Time         : value = TimeSpan.FromTicks(r.ReadInt64()); break;
              case SqlDbType.DateTimeOffset:
            DateTime LDateTime = DateTime.FromBinary(r.ReadInt64());
            value = new DateTimeOffset(LDateTime, TimeSpan.FromTicks(r.ReadInt64()));
            break;

              case SqlDbType.Decimal: value = new SqlDecimal(r.ReadDecimal()); break;
              case SqlDbType.Float  : value = new SqlDouble(r.ReadDouble()); break;
              // Not support SqlDbType.Image
              case SqlDbType.Money  : value = new SqlMoney(r.ReadDecimal()); break;
              case SqlDbType.Real   : value = new SqlSingle(r.ReadDouble()); break;
              case SqlDbType.SmallMoney: value = new SqlMoney(r.ReadDecimal()); break;
              // Not support SqlDbType.Structured
              // Not support SqlDbType.Text
              // Not support SqlDbType.Timestamp
              case SqlDbType.UniqueIdentifier: value = new SqlGuid(r.ReadString()); break;
              // Not support SqlDbType.Variant
              case SqlDbType.Xml:
            XmlReader rXml = XmlReader.Create(new System.IO.StringReader(r.ReadString()));
            value = new SqlXml(rXml);
            break;

              case SqlDbType.Udt:
            // TODO: Пока поддержа только TParams
            //String LTypeName = r.ReadString();
            //value = CreateUdtObject(LTypeName);
            //if (value is IBinarySerialize)
            //  (value as IBinarySerialize).Read(r);
            //else
            //  throw new Exception(String.Format("Невозможно прочитать данные типа UDT '{0}' - не поддерживается IBinarySerialize", LTypeName));
            value = new SqlUdt(r);
            break;

              default:
            throw new Exception(String.Format("Невозможно прочитать данные, тип '{0}' не поддерживается текущей версией {1}", LType.ToString(), this.GetType().Name));
              // Not support SqlDbType.NText
            }
            if (value != null) FData.Add(name, value);
              }

              return true;
        }
Exemplo n.º 2
0
 /// <summary>
 /// 使用 UserDefined 序列化格式
 /// 通过 IBinarySerialize.Read 方法完全控制二进制格式。
 /// 从用户定义类型 (UDT) 或用户定义聚合的二进制格式生成用户定义的类型或用户定义的聚合。 
 /// </summary>
 /// <param name="r"></param>
 public void Read(System.IO.BinaryReader r)
 {
     // 初始化数据.
     dataList = new List<decimal>();
     // 先读取总数量.
     int size = r.ReadInt32();
     // 依次读取数据,加入列表.
     for (int i = 0; i < size; i++)
     {
         dataList.Add(r.ReadDecimal());
     }
 }