示例#1
0
 public object Deserialize(Stream dataStream, Stream infoStream)
 {
     _reader        = new BinaryReader(dataStream);
     _serializeInfo = (SerializerInfo)_formatter.Deserialize(infoStream);
     _serializeInfo.InitId2Object();
     return(ReadObject());
 }
示例#2
0
        public object Deserialize(Stream dataStream)
        {
            _reader = new BinaryReader(dataStream);
            _reader.BaseStream.Position = _reader.BaseStream.Length - 4;
            int infoLen = _reader.ReadInt32();

            _reader.BaseStream.Position = _reader.BaseStream.Length - 4 - infoLen;
            byte[] bytes = _reader.ReadBytes(infoLen);
            var    ms    = new MemoryStream(bytes);

            _serializeInfo = (SerializerInfo)_formatter.Deserialize(ms);
            _serializeInfo.InitId2Object();
            _reader.BaseStream.Position = 0;

            return(ReadObject());
        }
示例#3
0
        private object ReadObject()
        {
            if (ReadNullNotNull())
            {
                return(null);
            }
            Type type = ReadObjectType();

            if (_serializeInfo.PrimativeValueTypes.Contains(type))
            {
                return(ReadPrimativeObject(type));
            }
            if (type == typeof(Comparer))
            {
                return(_serializeInfo.GetComparer());
            }

            if (typeof(Enum).Equals(type.BaseType))
            {
                return(ReadEnum(type));
            }

            if (type == typeof(TimeSpan))
            {
                return(new TimeSpan(_reader.ReadInt64()));
            }


            // REFERENCE TYPES
            int objectId = _reader.ReadInt32();

            object output = _serializeInfo.GetObjectById(objectId);

            if (output != null)
            {
                return(output);
            }
            if (type == typeof(string))
            {
                output = _reader.ReadString();
            }

            // TODO: If input is Array
            else if (type.IsArray)
            {
                output = ReadArray(type);
            }

            // TODO: If input is IDictionary<>/Dictionary<>
            else if (type.Name == "IDictionary`2" || type.Name == "Dictionary`2")
            {
                output = ReadDictionary(type);
            }
            // TODO: If input is List/IList
            else if (type.Name == "List`1" || type.Name == "IList`1")
            {
                output = ReadList(type);
            }

            // TODO: SortedList
            else if (type == typeof(SortedList))
            {
                output = ReadSortedList();
            }

            // TODO: if input is System.Drawing.Point
            else if (type == typeof(Point))
            {
                output = ReadDrawingPoint();
            }
            // TODO: Hashtable
            else if (type == typeof(Hashtable))
            {
                output = ReadHashtable();
            }

            // TODO: If input is ArrayList
            else if (SerializerInfo.IsBasedOn(type, typeof(ArrayList)))
            {
                output = ReadArrayList(type);
            }
            // TODO: If input is DictionaryBase
            else if (SerializerInfo.IsBasedOn(type, typeof(DictionaryBase)))
            {
                output = ReadDicionaryBase(type);
            }

            // TODO: CollectionBase
            else if (SerializerInfo.IsBasedOn(type, typeof(CollectionBase)))
            {
                output = ReadCollectionBase(type);
            }

            // TODO: Type that cannot create Instance by Activator
            else if (!_serializeInfo.CanCreateInstanceByActivator(type))
            {
                output = GeneralObjectDeserialize();
            }
            else
            {
                output = _serializeInfo.GetConstructor(type).Invoke(null);
                _serializeInfo.AddId2Object(objectId, output);

                // Read Fields
                ReadCustomFields(output, type);
            }

            _serializeInfo.AddId2Object(objectId, output);
            return(output);
        }
示例#4
0
 public Serializer()
 {
     SerializeInfo = new SerializerInfo();
 }
示例#5
0
 public RawDataWriter()
 {
     SerializeInfo = new SerializerInfo();
 }
示例#6
0
 public Serializer()
 {
     SerializeInfo = new SerializerInfo();
 }
示例#7
0
 public RawDataWriter()
 {
     SerializeInfo = new SerializerInfo();
 }