Ejemplo n.º 1
0
        public override void Write(BinSerializer bs, object instance)
        {
            var list = (IList)instance;

            //先写入元素个数
            VariantHelper.WriteInt32(list.Count, bs.Stream);
            //再写入各元素
            bs.WriteCollection(instance.GetType().GetGenericArguments()[0], list.Count, (index) => list[index]);
        }
Ejemplo n.º 2
0
        public override void Write(BinSerializer bs, object instance)
        {
            IDictionary dic = (IDictionary)instance;

            VariantHelper.WriteInt32(dic.Count, bs.Stream);
            foreach (var key in dic.Keys)
            {
                bs.Serialize(key);
                bs.Serialize(dic[key]);
            }
        }
Ejemplo n.º 3
0
 public void Write(BinSerializer bs, string instance)
 {
     if (instance == null)
     {
         VariantHelper.WriteInt32(-1, bs.Stream);
     }
     else if (instance == string.Empty)
     {
         VariantHelper.WriteInt32(0, bs.Stream);
     }
     else
     {
         VariantHelper.WriteInt32(instance.Length, bs.Stream);
         StringHelper.WriteTo(instance, b => bs.Stream.WriteByte(b));
     }
 }
Ejemplo n.º 4
0
        public override void Write(BinSerializer bs, object instance)
        {
            var array       = (Array)instance;
            var elementType = array.GetType().GetElementType();

            //先写入元素个数
            VariantHelper.WriteInt32(array.Length, bs.Stream);
            //再写入各元素
            if (elementType == typeof(Byte))
            {
                bs.Stream.Write((byte[])array, 0, array.Length);
            }
            else
            {
                bs.WriteCollection(elementType, array.Length, (index) => array.GetValue(index));
            }
        }
Ejemplo n.º 5
0
 public override void Write(BinSerializer bs, object instance)
 {
     VariantHelper.WriteInt32(Convert.ToInt32(instance), bs.Stream); //todo: fix Convert.ToInt32
 }
Ejemplo n.º 6
0
 public override void Write(BinSerializer bs, object obj)
 {
     VariantHelper.WriteInt32((int)obj, bs.Stream);
 }
Ejemplo n.º 7
0
 public void Write(BinSerializer bs, int obj)
 {
     VariantHelper.WriteInt32(obj, bs.Stream);
 }