Ejemplo n.º 1
0
        /// <summary>
        /// Serializes <see cref="value"/> into <see cref="output"/>.
        /// </summary>
        /// <typeparam name="T">The type of object to serialize.</typeparam>
        /// <param name="value">The object to serialize.</param>
        /// <param name="output">The stream to write to.</param>
        /// <exception cref="ArgumentNullException">
        ///		<para><paramref name="output"/> is <see langword="null"/>.</para>
        /// </exception>
        public static void Serialize <T>(T value, Stream output)
        {
            if (output == null)
            {
                throw new ArgumentNullException("output");
            }

            var serializer = BarfSerializers.Get <T>(PartFlags.None);
            var stream     = output.CanSeek ? output : new MemoryStream();
            var args       = new BarfSerializationArgs(SerializerFactory.GetWriter(stream));

            serializer.Serialize(value, args);

            if (!output.CanSeek)
            {
                output.Write(((MemoryStream)stream).GetBuffer(), 0, (int)stream.Length);
            }
        }
Ejemplo n.º 2
0
 public static void WritePart <T>(T part, BarfSerializationArgs args, PartFlags flags)
 {
     if (flags.IsSet(PartFlags.Dynamic))
     {
         if (!typeof(T).IsValueType && part == null)
         {
             args.Writer.WriteVarInt32(-1);
         }
         else
         {
             var type = part.GetType();
             args.Writer.WriteVarInt32(args.TypeTable.Include(type));
             var serializer = BarfSerializers.Get(type, flags & ~PartFlags.Dynamic);
             serializer.SerializeObject(part, args);
         }
     }
     else
     {
         BarfSerializers.Get <T>(flags).Serialize(part, args);
     }
 }
Ejemplo n.º 3
0
 public void SerializeObject(object instance, BarfSerializationArgs writeArgs)
 {
     Serialize((T)instance, writeArgs);
 }
Ejemplo n.º 4
0
 public abstract void Serialize(T instance, BarfSerializationArgs writeArgs);
Ejemplo n.º 5
0
 public override void Serialize(T instance, BarfSerializationArgs writeArgs)
 {
     _serializeMethod.Value(instance, writeArgs);
 }