コード例 #1
0
ファイル: BinaryFormatter.cs プロジェクト: dotnet/corefx
        internal object Deserialize(Stream serializationStream, bool check)
        {
            if (serializationStream == null)
            {
                throw new ArgumentNullException(nameof(serializationStream));
            }
            if (serializationStream.CanSeek && (serializationStream.Length == 0))
            {
                throw new SerializationException(SR.Serialization_Stream);
            }

            var formatterEnums = new InternalFE()
            {
                _typeFormat = _typeFormat,
                _serializerTypeEnum = InternalSerializerTypeE.Binary,
                _assemblyFormat = _assemblyFormat,
                _securityLevel = _securityLevel,
            };

            var reader = new ObjectReader(serializationStream, _surrogates, _context, formatterEnums, _binder)
            {
                _crossAppDomainArray = _crossAppDomainArray
            };
            var parser = new BinaryParser(serializationStream, reader);
            return reader.Deserialize(parser, check);
        }
コード例 #2
0
        internal object Deserialize(HeaderHandler handler, BinaryParser serParser, bool fCheck)
        {
            if (serParser == null)
            {
                throw new ArgumentNullException(nameof(serParser));
            }

            _fullDeserialization = false;
            TopObject = null;
            _topId = 0;

            _isSimpleAssembly = (_formatterEnums._assemblyFormat == FormatterAssemblyStyle.Simple);

            _handler = handler;

            if (_fullDeserialization)
            {
                // Reinitialize
                _objectManager = new ObjectManager(_surrogates, _context, false, false);
                _serObjectInfoInit = new SerObjectInfoInit();
            }

            // Will call back to ParseObject, ParseHeader for each object found
            serParser.Run();

            if (_fullDeserialization)
            {
                _objectManager.DoFixups();
            }

            if (TopObject == null)
            {
                throw new SerializationException(SR.Serialization_TopObject);
            }

            //if TopObject has a surrogate then the actual object may be changed during special fixup
            //So refresh it using topID.
            if (HasSurrogate(TopObject.GetType()) && _topId != 0)//Not yet resolved
            {
                TopObject = _objectManager.GetObject(_topId);
            }

            if (TopObject is IObjectReference)
            {
                TopObject = ((IObjectReference)TopObject).GetRealObject(_context);
            }

            if (_fullDeserialization)
            {
                _objectManager.RaiseDeserializationEvent(); // This will raise both IDeserialization and [OnDeserialized] events
            }

            // Return the headers if there is a handler
            if (handler != null)
            {
                _handlerObject = handler(_headers);
            }

            return TopObject;
        }
コード例 #3
0
        public void Read(BinaryParser input)
        {
            byte[] headerBytes = input.ReadBytes(17);

            // Throw if we couldnt read header bytes
            if (headerBytes.Length < 17)
            {
                throw new EndOfStreamException(SR.IO_EOF_ReadBeyondEOF);
            }

            _majorVersion = GetInt32(headerBytes, 9);
            if (_majorVersion > BinaryFormatterMajorVersion)
            {
                throw new SerializationException(SR.Format(SR.Serialization_InvalidFormat, BitConverter.ToString(headerBytes)));
            }

            // binaryHeaderEnum has already been read
            _binaryHeaderEnum = (BinaryHeaderEnum)headerBytes[0];
            _topId = GetInt32(headerBytes, 1);
            _headerId = GetInt32(headerBytes, 5);
            _minorVersion = GetInt32(headerBytes, 13);
        }
コード例 #4
0
ファイル: BinaryTypeConverter.cs プロジェクト: dotnet/corefx
        // Reads the type information from the wire
        internal static object ReadTypeInfo(BinaryTypeEnum binaryTypeEnum, BinaryParser input, out int assemId)
        {
            object var = null;
            int readAssemId = 0;

            switch (binaryTypeEnum)
            {
                case BinaryTypeEnum.Primitive:
                case BinaryTypeEnum.PrimitiveArray:
                    var = (InternalPrimitiveTypeE)input.ReadByte();
                    break;
                case BinaryTypeEnum.String:
                case BinaryTypeEnum.Object:
                case BinaryTypeEnum.StringArray:
                case BinaryTypeEnum.ObjectArray:
                    break;
                case BinaryTypeEnum.ObjectUrt:
                    var = input.ReadString();
                    break;
                case BinaryTypeEnum.ObjectUser:
                    var = input.ReadString();
                    readAssemId = input.ReadInt32();
                    break;
                default:
                    throw new SerializationException(SR.Format(SR.Serialization_TypeRead, binaryTypeEnum.ToString()));
            }
            assemId = readAssemId;
            return var;
        }
コード例 #5
0
 public void Read(BinaryParser input)
 {
     _assemId        = input.ReadInt32();
     _assemblyString = input.ReadString();
 }