Exemple #1
0
 public static void WriteObject(this Stream stream, object value, Type valueType, ValueSerializer valueSerializer,
                                bool preserveObjectReferences, SerializerSession session)
 {
     if (value == null) //value is null
     {
         NullSerializer.Instance.WriteManifest(stream, session);
     }
     else
     {
         int existingId;
         if (preserveObjectReferences && session.TryGetObjectId(value, out existingId))
         {
             //write the serializer manifest
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             //write the object reference id
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             var vType = value.GetType();
             var s2    = valueSerializer;
             if (vType != valueType)
             {
                 //value is of subtype, lookup the serializer for that type
                 s2 = session.Serializer.GetSerializerByType(vType);
             }
             //lookup serializer for subtype
             s2.WriteManifest(stream, session);
             s2.WriteValue(stream, value, session);
         }
     }
 }
Exemple #2
0
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         stream.WriteInt32(-1);
     }
     else
     {
         var type = (Type)value;
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, null, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             //type was not written before, add it to the tacked object list
             var name = type.GetShortAssemblyQualifiedName();
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             // ReSharper disable once PossibleNullReferenceException
             // ReSharper disable once AssignNullToNotNullAttribute
             var bytes = Encoding.UTF8.GetBytes(name);
             stream.WriteLengthEncodedByteArray(bytes);
         }
     }
 }
Exemple #3
0
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         StringSerializer.WriteValueImpl(stream, null, session);
     }
     else
     {
         var type = (Type)value;
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             //type was not written before, add it to the tacked object list
             var name = type.GetShortAssemblyQualifiedName();
             StringSerializer.WriteValueImpl(stream, name, session);
         }
     }
 }
Exemple #4
0
 public static void WriteObjectWithManifest(this Stream stream, object value, SerializerSession session)
 {
     if (value == null) //value is null
     {
         NullSerializer.Instance.WriteManifest(stream, session);
     }
     else
     {
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(value, out existingId))
         {
             //write the serializer manifest
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             //write the object reference id
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             var vType = value.GetType();
             var s2    = session.Serializer.GetSerializerByType(vType);
             s2.WriteManifest(stream, session);
             s2.WriteValue(stream, value, session);
         }
     }
 }
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         stream.WriteInt32(-1);
     }
     else
     {
         var type = (Type) value;
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, null, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         { 
             //type was not written before, add it to the tacked object list
             var name = type.GetShortAssemblyQualifiedName();
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             // ReSharper disable once PossibleNullReferenceException
             // ReSharper disable once AssignNullToNotNullAttribute
             var bytes = Encoding.UTF8.GetBytes(name);
             stream.WriteLengthEncodedByteArray(bytes);
         }
     }
 }
Exemple #6
0
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         StringSerializer.WriteValueImpl(stream,null,session);
     }
     else
     {
         var type = (Type) value;
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             //type was not written before, add it to the tacked object list
             var name = type.GetShortAssemblyQualifiedName();
             StringSerializer.WriteValueImpl(stream, name, session);
         }
     }
 }
 public override void WriteValue(Stream stream, object value, SerializerSession session)
 {
     if (value == null)
     {
         stream.WriteLengthEncodedByteArray(EmptyArray <byte> .Instance, session);
     }
     else
     {
         var type = (Type)value;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(type, out int existingId))
         {
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             if (session.Serializer.Options.PreserveObjectReferences)
             {
                 session.TrackSerializedObject(type);
             }
             //type was not written before, add it to the tacked object list
             var typeKey = AntTypeSerializer.GetTypeKeyFromType(type);
             stream.WriteLengthEncodedByteArray(typeKey.TypeName, session);
             Int32Serializer.WriteValueImpl(stream, typeKey.HashCode, session);
         }
     }
 }
Exemple #8
0
 public static void WriteObjectWithManifest(this Stream stream, object value, SerializerSession session)
 {
     if (value == null) //value is null
     {
         NullSerializer.Instance.WriteManifest(stream, session);
     }
     else
     {
         int existingId;
         if (session.Serializer.Options.PreserveObjectReferences && session.TryGetObjectId(value, out existingId))
         {
             //write the serializer manifest
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             //write the object reference id
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             var vType = value.GetType();
             var s2  = session.Serializer.GetSerializerByType(vType);
             s2.WriteManifest(stream, session);
             s2.WriteValue(stream, value, session);
         }
     }
 }
Exemple #9
0
 public static void WriteObject(this Stream stream, object value, Type valueType, ValueSerializer valueSerializer,
     bool preserveObjectReferences, SerializerSession session)
 {
     if (value == null) //value is null
     {
         NullSerializer.Instance.WriteManifest(stream, session);
     }
     else
     {
         int existingId;
         if (preserveObjectReferences && session.TryGetObjectId(value, out existingId))
         {
             //write the serializer manifest
             ObjectReferenceSerializer.Instance.WriteManifest(stream, session);
             //write the object reference id
             ObjectReferenceSerializer.Instance.WriteValue(stream, existingId, session);
         }
         else
         {
             var vType = value.GetType();
             var s2 = valueSerializer;
             if (vType != valueType)
             {
                 //value is of subtype, lookup the serializer for that type
                 s2 = session.Serializer.GetSerializerByType(vType);
             }
             //lookup serializer for subtype
             s2.WriteManifest(stream, session);
             s2.WriteValue(stream, value, session);
         }
     }
 }