예제 #1
0
        /// <summary>
        /// 反序列化类
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="reader">读取器</param>
        /// <returns>反序列化对象</returns>
        private static Object DeserializeClass(Type type, BitReader reader)
        {
            Boolean isNull = reader.ReadBit() == 1;

            if (!isNull)
            {
                BitSerializer serializer = new BitSerializer(type);
                return(serializer.Deserialize(reader));
            }
            return(null);
        }
예제 #2
0
 /// <summary>
 /// 返回从类型数组创建的 BitSerializer 对象的数组。
 /// </summary>
 /// <param name="types"></param>
 /// <returns></returns>
 public static BitSerializer[] FromTypes(Type[] types)
 {
     if (types == null)
     {
         throw new ArgumentNullException("types");
     }
     BitSerializer[] result = new BitSerializer[types.Length];
     for (int i = 0; i < types.Length; i++)
     {
         result[i] = new BitSerializer(types[i]);
     }
     return(result);
 }
예제 #3
0
        /// <summary>
        /// 序列化Class对象
        /// </summary>
        /// <param name="type"></param>
        /// <param name="o"></param>
        /// <param name="writer"></param>
        /// <param name="encoding"></param>
        private void SerializeClass(Type type, Object o, BitWriter writer, Encoding encoding)
        {
            if (type.Equals(m_Type))
            {
                return;
            }
            Boolean isNull = o == null || type.Equals(m_Type);

            writer.WriteBit(isNull ? 1 : 0);
            if (!isNull)
            {
                BitSerializer serializer = new BitSerializer(type);
                serializer.Serialize(writer, o, encoding);
            }
        }