Example #1
0
        public override void Serialize(Stream serializationStream, object graph)
        {
            if (graph is ISerializable serializableData)
            {
                SerializationInfo info = new SerializationInfo(graph.GetType(), new FormatterConverter());
                info.AddValue("$id", RefIdGenerator.GetId(graph, out _firstTime));
                info.AddValue("$type", graph.GetType().FullName);
                Context = new StreamingContext(StreamingContextStates.File);
                serializableData.GetObjectData(info, Context);
                foreach (SerializationEntry entry in info)
                {
                    WriteMember(entry.Name, entry.Value);
                }

                _fileContent += rowSeparator;

                while (m_objectQueue.Count != 0)
                {
                    Serialize(null, this.m_objectQueue.Dequeue());
                }

                if (m_objectQueue.Count == 0 && serializationStream != null)
                {
                    WriteDataToFile(_fileContent, serializationStream);
                }
            }
            else
            {
                throw new ArgumentException("Objects don't implement ISerializable");
            }
        }
Example #2
0
 protected override void WriteObjectRef(object obj, string name, Type memberType)
 {
     if (memberType.Equals(typeof(string)))
     {
         _fileContent += obj.GetType() + fieldInfoSeparator +
                         name + fieldInfoSeparator + (string)obj + fieldSeparator;
     }
     else
     {
         _fileContent += obj.GetType() + fieldInfoSeparator + name + fieldInfoSeparator +
                         RefIdGenerator.GetId(obj, out _firstTime) + fieldSeparator;
         if (_firstTime)
         {
             this.m_objectQueue.Enqueue(obj);
         }
     }
 }