private static ReadObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
 {
     return(new ReadObjectInfo()
     {
         objectInfoId = Interlocked.Increment(ref ReadObjectInfo.readObjectInfoCounter)
     });
 }
Beispiel #2
0
        // Read Constructor
        internal void Init(Type objectType, String[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 5 ", objectType);
            this.objectType         = objectType;
            this.objectManager      = objectManager;
            this.wireMemberNames    = memberNames;
            this.wireMemberTypes    = memberTypes;
            this.context            = context;
            this.serObjectInfoInit  = serObjectInfoInit;
            this.formatterConverter = converter;
            this.bSimpleAssembly    = bSimpleAssembly;
            if (memberNames != null)
            {
                isNamed = true;
            }
            if (memberTypes != null)
            {
                isTyped = true;
            }

            if (objectType != null)
            {
                InitReadConstructor(objectType, surrogateSelector, context);
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
        private static ReadObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            ReadObjectInfo roi = new ReadObjectInfo();

            roi.objectInfoId = readObjectInfoCounter++;
            return(roi);
        }
Beispiel #5
0
        private static ReadObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            ReadObjectInfo roi = new ReadObjectInfo();

            roi._objectInfoId = Interlocked.Increment(ref _readObjectInfoCounter);
            return(roi);
        }
        internal void Serialize(object graph, BinaryFormatterWriter serWriter, bool fCheck)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }
            if (serWriter == null)
            {
                throw new ArgumentNullException(nameof(serWriter));
            }

            _serWriter = serWriter;

            serWriter.WriteBegin();
            long   headerId = 0;
            object obj;
            long   objectId;
            bool   isNew;

            // allocations if methodCall or methodResponse and no graph
            _idGenerator        = new ObjectIDGenerator();
            _objectQueue        = new Queue <object>();
            _formatterConverter = new FormatterConverter();
            _serObjectInfoInit  = new SerObjectInfoInit();

            _topId   = InternalGetId(graph, false, null, out isNew);
            headerId = -1;
            WriteSerializedStreamHeader(_topId, headerId);

            _objectQueue.Enqueue(graph);
            while ((obj = GetNext(out objectId)) != null)
            {
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo.
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo          = WriteObjectInfo.Serialize(obj, _surrogates, _context, _serObjectInfoInit, _formatterConverter, this, _binder);
                    objectInfo._assemId = GetAssemblyId(objectInfo);
                }

                objectInfo._objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            // Invoke OnSerialized Event
            _objectManager.RaiseOnSerializedEvent();
        }
Beispiel #7
0
        internal void Serialize(object graph, BinaryFormatterWriter serWriter, bool fCheck)
        {
            if (graph == null)
            {
                throw new ArgumentNullException(nameof(graph));
            }
            if (serWriter == null)
            {
                throw new ArgumentNullException(nameof(serWriter));
            }

            _serWriter = serWriter;

            serWriter.WriteBegin();
            long headerId = 0;
            object obj;
            long objectId;
            bool isNew;

            // allocations if methodCall or methodResponse and no graph
            _idGenerator = new ObjectIDGenerator();
            _objectQueue = new Queue<object>();
            _formatterConverter = new FormatterConverter();
            _serObjectInfoInit = new SerObjectInfoInit();

            _topId = InternalGetId(graph, false, null, out isNew);
            headerId = -1;
            WriteSerializedStreamHeader(_topId, headerId);

            _objectQueue.Enqueue(graph);
            while ((obj = GetNext(out objectId)) != null)
            {
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo. 
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo = WriteObjectInfo.Serialize(obj, _surrogates, _context, _serObjectInfoInit, _formatterConverter, this, _binder);
                    objectInfo._assemId = GetAssemblyId(objectInfo);
                }

                objectInfo._objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            // Invoke OnSerialized Event
            _objectManager.RaiseOnSerializedEvent();
        }
 internal void Init(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
 {
     this.objectType         = objectType;
     this.objectManager      = objectManager;
     this.context            = context;
     this.serObjectInfoInit  = serObjectInfoInit;
     this.formatterConverter = converter;
     this.bSimpleAssembly    = bSimpleAssembly;
     this.InitReadConstructor(objectType, surrogateSelector, context);
 }
Beispiel #9
0
        // Write constructor
        internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 1 ", obj);
            this.context           = context;
            this.obj               = obj;
            this.serObjectInfoInit = serObjectInfoInit;
            ISurrogateSelector surrogateSelectorTemp;

            if (RemotingServices.IsTransparentProxy(obj))
            {
                objectType = Converter.typeofMarshalByRefObject;
            }
            else
            {
                objectType = obj.GetType();
            }

            if (objectType.IsArray)
            {
                isArray = true;
                InitNoMembers();
                return;
            }

            SerTrace.Log(this, objectInfoId, " Constructor 1 trace 2");

            objectWriter.ObjectManager.RegisterObject(obj);
            if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null)
            {
                SerTrace.Log(this, objectInfoId, " Constructor 1 trace 3");
                si = new SerializationInfo(objectType, converter);
                if (!objectType.IsPrimitive)
                {
                    serializationSurrogate.GetObjectData(obj, si, context);
                }
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!objectType.IsSerializable)
                {
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_NonSerType"),
                                                                   objectType.FullName, objectType.Assembly.FullName));
                }
                si = new SerializationInfo(objectType, converter);
                ((ISerializable)obj).GetObjectData(si, context);
                SerTrace.Log(this, objectInfoId, " Constructor 1 trace 4 ISerializable " + objectType);
                InitSiWrite();
            }
            else
            {
                SerTrace.Log(this, objectInfoId, " Constructor 1 trace 5");
                InitMemberInfo();
            }
        }
 private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
 {
     WriteObjectInfo info = null;
     if (!serObjectInfoInit.oiPool.IsEmpty())
     {
         info = (WriteObjectInfo) serObjectInfoInit.oiPool.Pop();
         info.InternalInit();
         return info;
     }
     return new WriteObjectInfo { objectInfoId = serObjectInfoInit.objectInfoIdCount++ };
 }
Beispiel #11
0
        internal static WriteObjectInfo Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            WriteObjectInfo     objectInfo         = WriteObjectInfo.GetObjectInfo(serObjectInfoInit);
            Type                objectType1        = objectType;
            ISurrogateSelector  surrogateSelector1 = surrogateSelector;
            StreamingContext    context1           = context;
            SerObjectInfoInit   serObjectInfoInit1 = serObjectInfoInit;
            IFormatterConverter converter1         = converter;
            SerializationBinder binder1            = binder;

            objectInfo.InitSerialize(objectType1, surrogateSelector1, context1, serObjectInfoInit1, converter1, binder1);
            return(objectInfo);
        }
        internal static WriteObjectInfo Serialize(
            [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type objectType,
            ISurrogateSelector?surrogateSelector,
            StreamingContext context,
            SerObjectInfoInit serObjectInfoInit,
            IFormatterConverter converter,
            SerializationBinder?binder)
        {
            WriteObjectInfo woi = GetObjectInfo(serObjectInfoInit);

            woi.InitSerialize(objectType, surrogateSelector, context, serObjectInfoInit, converter, binder);
            return(woi);
        }
Beispiel #13
0
        [System.Security.SecurityCritical]  // auto-generated
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 2 ", objectType);

            this.objectType        = objectType;
            this.context           = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                si    = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache(objectType);

                isSi = true;
            }
            else if (Object.ReferenceEquals(objectType, Converter.typeofObject))
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                si    = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
                cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);

                isSi = true;
            }

            if (!isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }

            SerTrace.Log(this, objectInfoId, " ", objectType, " InitSerialize Exit ", isSi);
        }
Beispiel #14
0
        private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            WriteObjectInfo info = null;

            if (!serObjectInfoInit.oiPool.IsEmpty())
            {
                info = (WriteObjectInfo)serObjectInfoInit.oiPool.Pop();
                info.InternalInit();
                return(info);
            }
            return(new WriteObjectInfo {
                objectInfoId = serObjectInfoInit.objectInfoIdCount++
            });
        }
Beispiel #15
0
 internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
 {
     this.context           = context;
     this.obj               = obj;
     this.serObjectInfoInit = serObjectInfoInit;
     if (RemotingServices.IsTransparentProxy(obj))
     {
         this.objectType = Converter.typeofMarshalByRefObject;
     }
     else
     {
         this.objectType = obj.GetType();
     }
     if (this.objectType.IsArray)
     {
         this.isArray = true;
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector;
         this.InvokeSerializationBinder(binder);
         objectWriter.ObjectManager.RegisterObject(obj);
         if ((surrogateSelector != null) && ((this.serializationSurrogate = surrogateSelector.GetSurrogate(this.objectType, context, out selector)) != null))
         {
             this.si = new SerializationInfo(this.objectType, converter);
             if (!this.objectType.IsPrimitive)
             {
                 this.serializationSurrogate.GetObjectData(obj, this.si, context);
             }
             this.InitSiWrite();
         }
         else if (obj is ISerializable)
         {
             if (!this.objectType.IsSerializable)
             {
                 throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[] { this.objectType.FullName, this.objectType.Assembly.FullName }));
             }
             this.si = new SerializationInfo(this.objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
             ((ISerializable)obj).GetObjectData(this.si, context);
             this.InitSiWrite();
             CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString);
         }
         else
         {
             this.InitMemberInfo();
             CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString);
         }
     }
 }
        internal static ReadObjectInfo Create(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            ReadObjectInfo      objectInfo         = ReadObjectInfo.GetObjectInfo(serObjectInfoInit);
            Type                objectType1        = objectType;
            ISurrogateSelector  surrogateSelector1 = surrogateSelector;
            StreamingContext    context1           = context;
            ObjectManager       objectManager1     = objectManager;
            SerObjectInfoInit   serObjectInfoInit1 = serObjectInfoInit;
            IFormatterConverter converter1         = converter;
            int num = bSimpleAssembly ? 1 : 0;

            objectInfo.Init(objectType1, surrogateSelector1, context1, objectManager1, serObjectInfoInit1, converter1, num != 0);
            return(objectInfo);
        }
Beispiel #17
0
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
        {
            SerTrace.Log(this, objectInfoId, " Constructor 2 ", objectType);

            this.objectType        = objectType;
            this.context           = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector != null)
            {
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (objectType == Converter.typeofObject)
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                isSi = true;
            }

            if (isSi)
            {
                si    = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache();
                cache.fullTypeName   = si.FullTypeName;
                cache.assemblyString = si.AssemblyName;
            }
            else
            {
                InitMemberInfo();
            }

            SerTrace.Log(this, objectInfoId, " ", objectType, " InitSerialize Exit ", isSi);
        }
Beispiel #18
0
        private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            WriteObjectInfo objectInfo;

            if (!serObjectInfoInit._oiPool.IsEmpty())
            {
                objectInfo = (WriteObjectInfo)serObjectInfoInit._oiPool.Pop();
                objectInfo.InternalInit();
            }
            else
            {
                objectInfo = new WriteObjectInfo();
                objectInfo._objectInfoId = serObjectInfoInit._objectInfoIdCount++;
            }

            return(objectInfo);
        }
        // Write Constructor used for array types or null members
        internal void InitSerialize(
            [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type objectType,
            ISurrogateSelector?surrogateSelector,
            StreamingContext context,
            SerObjectInfoInit serObjectInfoInit,
            IFormatterConverter converter,
            SerializationBinder?binder)
        {
            _objectType        = objectType;
            _context           = context;
            _serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            if (surrogateSelector != null)
            {
                _serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out ISurrogateSelector surrogateSelectorTemp);
            }

            if (_serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                _si    = new SerializationInfo(objectType, converter);
                _cache = new SerObjectInfoCache(objectType);
                _isSi  = true;
            }
            else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType))
            {
                _si    = new SerializationInfo(objectType, converter);
                _cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
                _isSi = true;
            }

            if (!_isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
            }
        }
Beispiel #20
0
        // Write constructor
        internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        {
            _context           = context;
            _obj               = obj;
            _serObjectInfoInit = serObjectInfoInit;
            _objectType        = obj.GetType();

            if (_objectType.IsArray)
            {
                _isArray = true;
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);
            objectWriter.ObjectManager.RegisterObject(obj);

            ISurrogateSelector surrogateSelectorTemp;

            if (surrogateSelector != null && (_serializationSurrogate = surrogateSelector.GetSurrogate(_objectType, context, out surrogateSelectorTemp)) != null)
            {
                _si = new SerializationInfo(_objectType, converter);
                if (!_objectType.IsPrimitive)
                {
                    _serializationSurrogate.GetObjectData(obj, _si, context);
                }
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!_objectType.IsSerializable)
                {
                    throw new SerializationException(SR.Format(SR.Serialization_NonSerType, _objectType.FullName, _objectType.Assembly.FullName));
                }
                _si = new SerializationInfo(_objectType, converter);
                ((ISerializable)obj).GetObjectData(_si, context);
                InitSiWrite();
                CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString);
            }
            else
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString);
            }
        }
Beispiel #21
0
        // Write constructor
        internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        {
            _context = context;
            _obj = obj;
            _serObjectInfoInit = serObjectInfoInit;
            _objectType = obj.GetType();

            if (_objectType.IsArray)
            {
                _isArray = true;
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);
            objectWriter.ObjectManager.RegisterObject(obj);

            ISurrogateSelector surrogateSelectorTemp;
            if (surrogateSelector != null && (_serializationSurrogate = surrogateSelector.GetSurrogate(_objectType, context, out surrogateSelectorTemp)) != null)
            {
                _si = new SerializationInfo(_objectType, converter);
                if (!_objectType.IsPrimitive)
                {
                    _serializationSurrogate.GetObjectData(obj, _si, context);
                }
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!_objectType.IsSerializable)
                {
                    throw new SerializationException(SR.Format(SR.Serialization_NonSerType, _objectType.FullName, _objectType.Assembly.FullName));
                }
                _si = new SerializationInfo(_objectType, converter);
                ((ISerializable)obj).GetObjectData(_si, context);
                InitSiWrite();
                CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString);
            }
            else
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(_cache, _objectType, _binderAssemblyString);
            }
        }
        // Token: 0x060053B1 RID: 21425 RVA: 0x00128C9C File Offset: 0x00126E9C
        private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            WriteObjectInfo writeObjectInfo;

            if (!serObjectInfoInit.oiPool.IsEmpty())
            {
                writeObjectInfo = (WriteObjectInfo)serObjectInfoInit.oiPool.Pop();
                writeObjectInfo.InternalInit();
            }
            else
            {
                writeObjectInfo = new WriteObjectInfo();
                WriteObjectInfo writeObjectInfo2  = writeObjectInfo;
                int             objectInfoIdCount = serObjectInfoInit.objectInfoIdCount;
                serObjectInfoInit.objectInfoIdCount = objectInfoIdCount + 1;
                writeObjectInfo2.objectInfoId       = objectInfoIdCount;
            }
            return(writeObjectInfo);
        }
Beispiel #23
0
        private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            WriteObjectInfo objectInfo = null;

            if (!serObjectInfoInit.oiPool.IsEmpty())
            {
                objectInfo = (WriteObjectInfo)serObjectInfoInit.oiPool.Pop();
                objectInfo.InternalInit();
                //SerTrace.Log( "GetObjectInfo",objectInfo.objectInfoId," GetObjectInfo from pool");
            }
            else
            {
                objectInfo = new WriteObjectInfo();
                objectInfo.objectInfoId = serObjectInfoInit.objectInfoIdCount++;
                //SerTrace.Log( "GetObjectInfo",objectInfo.objectInfoId," GetObjectInfo new not from pool");
            }

            return(objectInfo);
        }
Beispiel #24
0
 internal void Init(Type objectType, string[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
 {
     _objectType         = objectType;
     _objectManager      = objectManager;
     _wireMemberNames    = memberNames;
     _wireMemberTypes    = memberTypes;
     _context            = context;
     _serObjectInfoInit  = serObjectInfoInit;
     _formatterConverter = converter;
     _isSimpleAssembly   = bSimpleAssembly;
     if (memberTypes != null)
     {
         _isTyped = true;
     }
     if (objectType != null)
     {
         InitReadConstructor(objectType, surrogateSelector, context);
     }
 }
Beispiel #25
0
        private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            WriteObjectInfo writeObjectInfo1;

            if (!serObjectInfoInit.oiPool.IsEmpty())
            {
                writeObjectInfo1 = (WriteObjectInfo)serObjectInfoInit.oiPool.Pop();
                writeObjectInfo1.InternalInit();
            }
            else
            {
                writeObjectInfo1 = new WriteObjectInfo();
                WriteObjectInfo   writeObjectInfo2   = writeObjectInfo1;
                SerObjectInfoInit serObjectInfoInit1 = serObjectInfoInit;
                int num1 = serObjectInfoInit1.objectInfoIdCount;
                int num2 = num1 + 1;
                serObjectInfoInit1.objectInfoIdCount = num2;
                int num3 = num1;
                writeObjectInfo2.objectInfoId = num3;
            }
            return(writeObjectInfo1);
        }
Beispiel #26
0
 internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
 {
     this.objectType        = objectType;
     this.context           = context;
     this.serObjectInfoInit = serObjectInfoInit;
     if (objectType.IsArray)
     {
         this.InitNoMembers();
     }
     else
     {
         this.InvokeSerializationBinder(binder);
         ISurrogateSelector selector = (ISurrogateSelector)null;
         if (surrogateSelector != null)
         {
             this.serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out selector);
         }
         if (this.serializationSurrogate != null)
         {
             this.si    = new SerializationInfo(objectType, converter);
             this.cache = new SerObjectInfoCache(objectType);
             this.isSi  = true;
         }
         else if (objectType != Converter.typeofObject && Converter.typeofISerializable.IsAssignableFrom(objectType))
         {
             this.si    = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
             this.cache = new SerObjectInfoCache(objectType);
             WriteObjectInfo.CheckTypeForwardedFrom(this.cache, objectType, this.binderAssemblyString);
             this.isSi = true;
         }
         if (this.isSi)
         {
             return;
         }
         this.InitMemberInfo();
         WriteObjectInfo.CheckTypeForwardedFrom(this.cache, objectType, this.binderAssemblyString);
     }
 }
Beispiel #27
0
 private static void PutObjectInfo(SerObjectInfoInit serObjectInfoInit, WriteObjectInfo objectInfo) =>
 serObjectInfoInit._oiPool.Push(objectInfo);
Beispiel #28
0
        internal static WriteObjectInfo Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
        {
            WriteObjectInfo soi = GetObjectInfo(serObjectInfoInit);

            soi.InitSerialize(obj, surrogateSelector, context, serObjectInfoInit, converter);
            return(soi);
        }
Beispiel #29
0
 private static void PutObjectInfo(SerObjectInfoInit serObjectInfoInit, WriteObjectInfo objectInfo)
 {
     serObjectInfoInit.oiPool.Push(objectInfo);
     //SerTrace.Log( "PutObjectInfo",objectInfo.objectInfoId," PutObjectInfo to pool");
 }
 private static ReadObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
 {
     return new ReadObjectInfo { objectInfoId = readObjectInfoCounter++ };
 }
 internal static ReadObjectInfo Create(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
 {
     ReadObjectInfo objectInfo = GetObjectInfo(serObjectInfoInit);
     objectInfo.Init(objectType, surrogateSelector, context, objectManager, serObjectInfoInit, converter, bSimpleAssembly);
     return objectInfo;
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, bool fCheck)
        {
            if (graph == null)
                throw new ArgumentNullException("graph", Environment.GetResourceString("ArgumentNull_Graph"));

            if (serWriter == null)
                throw new ArgumentNullException("serWriter", Environment.GetResourceString("ArgumentNull_WithParamName", "serWriter"));
            Contract.EndContractBlock();

            SerTrace.Log(this, "Serialize Entry 2 ", graph, ((headers == null) ? " no headers " : "headers "));

            if (fCheck)
            {
                CodeAccessPermission.Demand(PermissionType.SecuritySerialization);          
            }

            this.serWriter = serWriter;
            this.headers = inHeaders;

            SerTrace.Log( this, "Serialize New SerializedTypeTable");
            serWriter.WriteBegin();
            long headerId = 0;
            Object obj;
            long objectId;
            bool isNew;
            bool bMethodCall = false;
            bool bMethodReturn = false;

#if FEATURE_REMOTING        
            // Special case IMethodCallMessage and IMethodReturnMessage for performance
            IMethodCallMessage mess = graph as IMethodCallMessage;
            if (mess != null)
            {
                bMethodCall = true;
                graph = WriteMethodCall(mess);
            }
            else
            {
                IMethodReturnMessage mr = graph as IMethodReturnMessage;
                if (mr != null)
                {
                    bMethodReturn = true;
                    graph = WriteMethodReturn(mr);
                }
            }
#endif // FEATURE_REMOTING        

            if (graph == null)
            {
                WriteSerializedStreamHeader(topId, headerId);

                if (bMethodCall)
                    serWriter.WriteMethodCall();
                else if (bMethodReturn)
                    serWriter.WriteMethodReturn();

                serWriter.WriteSerializationHeaderEnd();
                serWriter.WriteEnd();
                return;
            }

            // allocations if methodCall or methodResponse and no graph
            m_idGenerator = new ObjectIDGenerator();
            m_objectQueue = new Queue();
            m_formatterConverter = new FormatterConverter();
            serObjectInfoInit = new SerObjectInfoInit();        

            topId = InternalGetId(graph, false, null, out isNew);


            if (headers != null)
                headerId = InternalGetId(headers, false, null, out isNew);
            else
                headerId = -1;

            WriteSerializedStreamHeader(topId, headerId);


            if (bMethodCall)
                serWriter.WriteMethodCall();
            else if (bMethodReturn)
                serWriter.WriteMethodReturn();


            SerTrace.Log( this, "Serialize Schedule 0");
            // Write out SerializedStream header
            if ((headers != null) && (headers.Length > 0))
                m_objectQueue.Enqueue(headers);                 

            if (graph != null)
                m_objectQueue.Enqueue(graph);
            while ((obj = GetNext(out objectId))!=null)
            {
                SerTrace.Log( this, "Serialize GetNext ",obj);
                WriteObjectInfo objectInfo = null;

                // GetNext will return either an object or a WriteObjectInfo. 
                // A WriteObjectInfo is returned if this object was member of another object
                if (obj is WriteObjectInfo)
                {
                    SerTrace.Log( this, "Serialize GetNext recognizes WriteObjectInfo");
                    objectInfo = (WriteObjectInfo)obj;
                }
                else
                {
                    objectInfo = WriteObjectInfo.Serialize(obj, m_surrogates, m_context, serObjectInfoInit, m_formatterConverter, this, m_binder);
                    objectInfo.assemId = GetAssemblyId(objectInfo);
                }


                objectInfo.objectId = objectId;
                NameInfo typeNameInfo = TypeToNameInfo(objectInfo);
                Write(objectInfo, typeNameInfo, typeNameInfo);
                PutNameInfo(typeNameInfo);
                objectInfo.ObjectEnd();
            }

            serWriter.WriteSerializationHeaderEnd();
            serWriter.WriteEnd();

            // Invoke OnSerialized Event
            m_objectManager.RaiseOnSerializedEvent();
            
            SerTrace.Log( this, "Serialize Exit ");
        }
Beispiel #33
0
 internal void Init(Type objectType, string[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
 {
     _objectType = objectType;
     _objectManager = objectManager;
     _wireMemberNames = memberNames;
     _wireMemberTypes = memberTypes;
     _context = context;
     _serObjectInfoInit = serObjectInfoInit;
     _formatterConverter = converter;
     _isSimpleAssembly = bSimpleAssembly;
     if (memberTypes != null)
     {
         _isTyped = true;
     }
     if (objectType != null)
     {
         InitReadConstructor(objectType, surrogateSelector, context);
     }
 }
Beispiel #34
0
        private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            WriteObjectInfo objectInfo;

            if (!serObjectInfoInit._oiPool.IsEmpty())
            {
                objectInfo = (WriteObjectInfo)serObjectInfoInit._oiPool.Pop();
                objectInfo.InternalInit();
            }
            else
            {
                objectInfo = new WriteObjectInfo();
                objectInfo._objectInfoId = serObjectInfoInit._objectInfoIdCount++;
            }

            return objectInfo;
        }
        internal Object Deserialize(HeaderHandler handler, __BinaryParser serParser, bool fCheck)
        {
            if (serParser == null)
                throw new ArgumentNullException("serParser", Environment.GetResourceString("ArgumentNull_WithParamName", serParser)); 
            Contract.EndContractBlock();
 
#if _DEBUG 
            SerTrace.Log( this, "Deserialize Entry handler", handler);
#endif 
            bFullDeserialization = false;
            TopObject = null;
            topId = 0;
#if FEATURE_REMOTING 
            bMethodCall = false;
            bMethodReturn = false; 
            bIsCrossAppDomain = isCrossAppDomain; 
#endif
            bSimpleAssembly =  (formatterEnums.FEassemblyFormat == FormatterAssemblyStyle.Simple); 

            if (fCheck)
            {
                try{ 
                    CodeAccessPermission.Demand(PermissionType.SecuritySerialization);
                }catch(Exception e) 
                { 
                    deserializationSecurityException = e;
                } 
            }

            this.handler = handler;
 

            if (bFullDeserialization) 
            { 
                // Reinitialize
#if FEATURE_REMOTING 
                m_objectManager = new ObjectManager(m_surrogates, m_context, false, bIsCrossAppDomain);
#else
                m_objectManager = new ObjectManager(m_surrogates, m_context, false, false);
#endif 
                serObjectInfoInit = new SerObjectInfoInit();
            } 
 
            // Will call back to ParseObject, ParseHeader for each object found
            serParser.Run(); 

#if _DEBUG
            SerTrace.Log( this, "Deserialize Finished Parsing DoFixups");
#endif 

            if (bFullDeserialization) 
                m_objectManager.DoFixups(); 

 
#if FEATURE_REMOTING
            if (!bMethodCall && !bMethodReturn)
#endif
            { 
                if (TopObject == null)
                    throw new SerializationException(Environment.GetResourceString("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 = m_objectManager.GetObject(topId);

                if (TopObject is IObjectReference) 
                {
                    TopObject = ((IObjectReference)TopObject).GetRealObject(m_context); 
                } 
            }
 
            SerTrace.Log( this, "Deserialize Exit ",TopObject);

            if (bFullDeserialization)
            { 
                m_objectManager.RaiseDeserializationEvent(); // This will raise both IDeserialization and [OnDeserialized] events
            } 
 
            // Return the headers if there is a handler
            if (handler != null) 
            {
                handlerObject = handler(headers);
            }
#if FEATURE_REMOTING 
            if (bMethodCall)
            { 
                Object[] methodCallArray = TopObject as Object[]; 
                TopObject = binaryMethodCall.ReadArray(methodCallArray, handlerObject);
            } 
            else if (bMethodReturn)
            {
                Object[] methodReturnArray = TopObject as Object[];
                TopObject = binaryMethodReturn.ReadArray(methodReturnArray, methodCallMessage, handlerObject); 
            }
#endif 
            return TopObject; 
        }
        internal static WriteObjectInfo Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
        {
            WriteObjectInfo soi = GetObjectInfo(serObjectInfoInit);

            soi.InitSerialize(obj, surrogateSelector, context, serObjectInfoInit, converter, objectWriter);
            return soi;
        }
Beispiel #37
0
 private static void PutObjectInfo(SerObjectInfoInit serObjectInfoInit, WriteObjectInfo objectInfo) =>
     serObjectInfoInit._oiPool.Push(objectInfo);
        [System.Security.SecurityCritical]  // auto-generated
        internal void Init(Type objectType, String[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            SerTrace.Log( this,objectInfoId, " Constructor 5 ",objectType);
            this.objectType = objectType;
            this.objectManager = objectManager;
            this.wireMemberNames = memberNames;
            this.wireMemberTypes = memberTypes;
            this.context = context;
            this.serObjectInfoInit = serObjectInfoInit;
            this.formatterConverter = converter;
            this.bSimpleAssembly = bSimpleAssembly;
            if (memberNames != null)
                isNamed = true;
            if (memberTypes != null)
                isTyped = true;

            if ((object)objectType != null)
                InitReadConstructor(objectType, surrogateSelector, context);
        }
 private static ReadObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
 {
     ReadObjectInfo roi =  new ReadObjectInfo();
     roi.objectInfoId = readObjectInfoCounter++;
     return roi;
 }
Beispiel #40
0
        internal void Init(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            _objectType = objectType;
            _objectManager = objectManager;
            _context = context;
            _serObjectInfoInit = serObjectInfoInit;
            _formatterConverter = converter;
            _isSimpleAssembly = bSimpleAssembly;

            InitReadConstructor(objectType, surrogateSelector, context);
        }
 [System.Security.SecurityCritical]  // auto-generated
 internal static ReadObjectInfo Create(Type objectType, String[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
 {
     ReadObjectInfo soi = GetObjectInfo(serObjectInfoInit);
     soi.Init(objectType, memberNames,memberTypes, surrogateSelector, context, objectManager, serObjectInfoInit, converter, bSimpleAssembly);
     return soi;
 }
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)
        {

            SerTrace.Log( this, objectInfoId," Constructor 2 ",objectType);

            this.objectType = objectType;
            this.context = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector!=null)
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);

            if (serializationSurrogate != null)
            {
                isSi = true;
            }
            else if (objectType == Converter.typeofObject)
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
                isSi = true;

            if (isSi)
            {
		    si = new SerializationInfo(objectType, converter);
		    cache = new SerObjectInfoCache();
		    cache.fullTypeName = si.FullTypeName;
		    cache.assemblyString = si.AssemblyName;
            }
            else
            {
                InitMemberInfo();
            }

            SerTrace.Log( this,objectInfoId," ", objectType," InitSerialize Exit ",isSi);
        }
 private static ReadObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
 {
     ReadObjectInfo roi =  new ReadObjectInfo();
     roi.objectInfoId = Interlocked.Increment(ref readObjectInfoCounter);
     return roi;
 }
        internal static ReadObjectInfo Create(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            ReadObjectInfo objectInfo = GetObjectInfo(serObjectInfoInit);

            objectInfo.Init(objectType, surrogateSelector, context, objectManager, serObjectInfoInit, converter, bSimpleAssembly);
            return(objectInfo);
        }
Beispiel #45
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;
        }
Beispiel #46
0
        // Deserialize the stream into an object graph.
        internal Object Deserialize(HeaderHandler handler, __BinaryParser serParser, bool fCheck, IMethodCallMessage methodCallMessage)
        {

            SerTrace.Log( this, "Deserialize Entry handler", handler);

            BCLDebug.Assert((IsCrossAppDomain() && (crossAppDomainArray != null))
                            || (!IsCrossAppDomain()),
                             "[System.Runtime.Serialization.Formatters.BinaryObjectReader missing crossAppDomainArray]");

            bFullDeserialization = false;
            bMethodCall = false;
            bMethodReturn = false;
            bSimpleAssembly =  (formatterEnums.FEassemblyFormat == FormatterAssemblyStyle.Simple);

            if (serParser == null)
                throw new ArgumentNullException("serParser", String.Format(Environment.GetResourceString("ArgumentNull_WithParamName"), serParser));

            if (fCheck)
            {
                try{
                    CodeAccessPermission.DemandInternal(PermissionType.SecuritySerialization);          
                }catch(Exception e)
                {
                    deserializationSecurityException = e;
                }
            }

            this.handler = handler;

            if (bFullDeserialization)
            {
                // Reinitialize
                m_objectManager = new ObjectManager(m_surrogates, m_context, false);
                serObjectInfoInit = new SerObjectInfoInit();
            }


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

            SerTrace.Log( this, "Deserialize Finished Parsing DoFixups");

            if (bFullDeserialization)
                m_objectManager.DoFixups();

            if (!bMethodCall && !bMethodReturn)
            {
                if (topObject == null)
                    throw new SerializationException(Environment.GetResourceString("Serialization_TopObject"));

                if (topObject is IObjectReference)
                {
                    topObject = ((IObjectReference)topObject).GetRealObject(m_context);
                }
            }

            SerTrace.Log( this, "Deserialize Exit ",topObject);

            if (bFullDeserialization)
                m_objectManager.RaiseDeserializationEvent();

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

            if (bMethodCall)
            {
                Object[] methodCallArray = topObject as Object[];
                topObject = binaryMethodCall.ReadArray(methodCallArray, handlerObject);
            }
            else if (bMethodReturn)
            {
                Object[] methodReturnArray = topObject as Object[];
                topObject = binaryMethodReturn.ReadArray(methodReturnArray, methodCallMessage, handlerObject);
            }

            return topObject;
        }
 internal object Deserialize(HeaderHandler handler, __BinaryParser serParser, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage)
 {
     if (serParser == null)
     {
         throw new ArgumentNullException("serParser", Environment.GetResourceString("ArgumentNull_WithParamName", new object[] { serParser }));
     }
     this.bFullDeserialization = false;
     this.TopObject = null;
     this.topId = 0L;
     this.bMethodCall = false;
     this.bMethodReturn = false;
     this.bIsCrossAppDomain = isCrossAppDomain;
     this.bSimpleAssembly = this.formatterEnums.FEassemblyFormat == FormatterAssemblyStyle.Simple;
     if (fCheck)
     {
         CodeAccessPermission.Demand(PermissionType.SecuritySerialization);
     }
     this.handler = handler;
     if (this.bFullDeserialization)
     {
         this.m_objectManager = new ObjectManager(this.m_surrogates, this.m_context, false, this.bIsCrossAppDomain);
         this.serObjectInfoInit = new SerObjectInfoInit();
     }
     serParser.Run();
     if (this.bFullDeserialization)
     {
         this.m_objectManager.DoFixups();
     }
     if (!this.bMethodCall && !this.bMethodReturn)
     {
         if (this.TopObject == null)
         {
             throw new SerializationException(Environment.GetResourceString("Serialization_TopObject"));
         }
         if (this.HasSurrogate(this.TopObject.GetType()) && (this.topId != 0L))
         {
             this.TopObject = this.m_objectManager.GetObject(this.topId);
         }
         if (this.TopObject is IObjectReference)
         {
             this.TopObject = ((IObjectReference) this.TopObject).GetRealObject(this.m_context);
         }
     }
     if (this.bFullDeserialization)
     {
         this.m_objectManager.RaiseDeserializationEvent();
     }
     if (handler != null)
     {
         this.handlerObject = handler(this.headers);
     }
     if (this.bMethodCall)
     {
         object[] topObject = this.TopObject as object[];
         this.TopObject = this.binaryMethodCall.ReadArray(topObject, this.handlerObject);
     }
     else if (this.bMethodReturn)
     {
         object[] returnA = this.TopObject as object[];
         this.TopObject = this.binaryMethodReturn.ReadArray(returnA, methodCallMessage, this.handlerObject);
     }
     return this.TopObject;
 }
        // Write constructor
        internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
        {
            SerTrace.Log( this, objectInfoId," Constructor 1 ",obj);
            this.context = context;
            this.obj = obj;
            this.serObjectInfoInit = serObjectInfoInit;
            ISurrogateSelector surrogateSelectorTemp;

            if (RemotingServices.IsTransparentProxy(obj))
                objectType = Converter.typeofMarshalByRefObject;
            else
                objectType = obj.GetType();

            if (objectType.IsArray)
            {
                isArray = true;
                InitNoMembers();
                return;
            }

            SerTrace.Log( this, objectInfoId," Constructor 1 trace 2");

            objectWriter.ObjectManager.RegisterObject(obj);
            if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null)
            {
                SerTrace.Log( this, objectInfoId," Constructor 1 trace 3");
                si = new SerializationInfo(objectType, converter);
                if (!objectType.IsPrimitive)
                    serializationSurrogate.GetObjectData(obj, si, context);
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!objectType.IsSerializable) {
                    throw new SerializationException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Serialization_NonSerType"),
                                                                   objectType.FullName, objectType.Assembly.FullName));
                }
                si = new SerializationInfo(objectType, converter);
                ((ISerializable)obj).GetObjectData(si, context);
                SerTrace.Log( this, objectInfoId," Constructor 1 trace 4 ISerializable "+objectType);
                InitSiWrite();
            }
            else
            {
                SerTrace.Log(this, objectInfoId," Constructor 1 trace 5");
                InitMemberInfo();
            }
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal void InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        {
            SerTrace.Log( this, objectInfoId," Constructor 1 ",obj);
            this.context = context;
            this.obj = obj;
            this.serObjectInfoInit = serObjectInfoInit;
            ISurrogateSelector surrogateSelectorTemp;

#if  FEATURE_REMOTING        
            if (RemotingServices.IsTransparentProxy(obj))
                objectType = Converter.typeofMarshalByRefObject;
            else
#endif
                objectType = obj.GetType();

            if (objectType.IsArray)
            {
                isArray = true;
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            SerTrace.Log( this, objectInfoId," Constructor 1 trace 2");

            objectWriter.ObjectManager.RegisterObject(obj);
            if (surrogateSelector != null && (serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp)) != null)
            {
                SerTrace.Log( this, objectInfoId," Constructor 1 trace 3");
                si = new SerializationInfo(objectType, converter);
                if (!objectType.IsPrimitive)
                    serializationSurrogate.GetObjectData(obj, si, context);
                InitSiWrite();
            }
            else if (obj is ISerializable)
            {
                if (!objectType.IsSerializable) {
                    throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType",
                                                                   objectType.FullName, objectType.Assembly.FullName));
                }
                si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
#if FEATURE_SERIALIZATION
                ((ISerializable)obj).GetObjectData(si, context);
#endif
                SerTrace.Log( this, objectInfoId," Constructor 1 trace 4 ISerializable "+objectType);
                InitSiWrite();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }
            else
            {
                SerTrace.Log(this, objectInfoId," Constructor 1 trace 5");
                InitMemberInfo();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }
        }
 [System.Security.SecurityCritical]  // auto-generated
 internal static WriteObjectInfo Serialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
 {
     WriteObjectInfo soi = GetObjectInfo(serObjectInfoInit);
     soi.InitSerialize(objectType, surrogateSelector, context, serObjectInfoInit, converter, binder);
     return soi;
 }
 internal static WriteObjectInfo Serialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
 {
     WriteObjectInfo objectInfo = GetObjectInfo(serObjectInfoInit);
     objectInfo.InitSerialize(obj, surrogateSelector, context, serObjectInfoInit, converter, objectWriter, binder);
     return objectInfo;
 }
        [System.Security.SecurityCritical]  // auto-generated
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {

            SerTrace.Log( this, objectInfoId," Constructor 2 ",objectType);

            this.objectType = objectType;
            this.context = context;
            this.serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;

            if (surrogateSelector!=null)
                serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);

            if (serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                si = new SerializationInfo(objectType, converter);
                cache = new SerObjectInfoCache(objectType);

                isSi = true;
            }
            else if (Object.ReferenceEquals(objectType, Converter.typeofObject))
            {
            }
            else if (Converter.typeofISerializable.IsAssignableFrom(objectType))
            {
                si = new SerializationInfo(objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
                cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);

                isSi = true;
            }

            if (!isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(cache, objectType, binderAssemblyString);
            }

            SerTrace.Log( this,objectInfoId," ", objectType," InitSerialize Exit ",isSi);
        }
 internal void InitSerialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
 {
     this.context = context;
     this.obj = obj;
     this.serObjectInfoInit = serObjectInfoInit;
     if (RemotingServices.IsTransparentProxy(obj))
     {
         this.objectType = Converter.typeofMarshalByRefObject;
     }
     else
     {
         this.objectType = obj.GetType();
     }
     if (this.objectType.IsArray)
     {
         this.isArray = true;
         this.InitNoMembers();
     }
     else
     {
         ISurrogateSelector selector;
         this.InvokeSerializationBinder(binder);
         objectWriter.ObjectManager.RegisterObject(obj);
         if ((surrogateSelector != null) && ((this.serializationSurrogate = surrogateSelector.GetSurrogate(this.objectType, context, out selector)) != null))
         {
             this.si = new SerializationInfo(this.objectType, converter);
             if (!this.objectType.IsPrimitive)
             {
                 this.serializationSurrogate.GetObjectData(obj, this.si, context);
             }
             this.InitSiWrite();
         }
         else if (obj is ISerializable)
         {
             if (!this.objectType.IsSerializable)
             {
                 throw new SerializationException(Environment.GetResourceString("Serialization_NonSerType", new object[] { this.objectType.FullName, this.objectType.Assembly.FullName }));
             }
             this.si = new SerializationInfo(this.objectType, converter, !FormatterServices.UnsafeTypeForwardersIsEnabled());
             ((ISerializable) obj).GetObjectData(this.si, context);
             this.InitSiWrite();
             CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString);
         }
         else
         {
             this.InitMemberInfo();
             CheckTypeForwardedFrom(this.cache, this.objectType, this.binderAssemblyString);
         }
     }
 }
        private static WriteObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
        {
            WriteObjectInfo objectInfo = null;

            if (!serObjectInfoInit.oiPool.IsEmpty())
            {
                objectInfo = (WriteObjectInfo)serObjectInfoInit.oiPool.Pop();
                objectInfo.InternalInit();
                //SerTrace.Log( "GetObjectInfo",objectInfo.objectInfoId," GetObjectInfo from pool");
            }
            else
            {
                objectInfo = new WriteObjectInfo();
                objectInfo.objectInfoId = serObjectInfoInit.objectInfoIdCount++;
                //SerTrace.Log( "GetObjectInfo",objectInfo.objectInfoId," GetObjectInfo new not from pool");
            }

            return objectInfo;
        }
Beispiel #55
0
        internal static ReadObjectInfo Create(Type objectType, string[] memberNames, Type[] memberTypes, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {
            ReadObjectInfo roi = GetObjectInfo(serObjectInfoInit);

            roi.Init(objectType, memberNames, memberTypes, surrogateSelector, context, objectManager, serObjectInfoInit, converter, bSimpleAssembly);
            return(roi);
        }
 private static void PutObjectInfo(SerObjectInfoInit serObjectInfoInit, WriteObjectInfo objectInfo)
 {
     serObjectInfoInit.oiPool.Push(objectInfo);
     //SerTrace.Log( "PutObjectInfo",objectInfo.objectInfoId," PutObjectInfo to pool");
 }
Beispiel #57
0
        internal static WriteObjectInfo Serialize(object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter, SerializationBinder binder)
        {
            WriteObjectInfo woi = GetObjectInfo(serObjectInfoInit);

            woi.InitSerialize(obj, surrogateSelector, context, serObjectInfoInit, converter, objectWriter, binder);
            return(woi);
        }
        [System.Security.SecurityCritical]  // auto-generated
        internal void Init(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, ObjectManager objectManager, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, bool bSimpleAssembly)
        {

            SerTrace.Log( this, objectInfoId," Constructor 3 ",objectType);

            this.objectType = objectType;
            this.objectManager = objectManager;
            this.context = context;
            this.serObjectInfoInit = serObjectInfoInit;
            this.formatterConverter = converter;
            this.bSimpleAssembly = bSimpleAssembly;

            InitReadConstructor(objectType, surrogateSelector, context);
        }
 private static ReadObjectInfo GetObjectInfo(SerObjectInfoInit serObjectInfoInit)
 {
     return(new ReadObjectInfo {
         objectInfoId = readObjectInfoCounter++
     });
 }
Beispiel #60
0
        // Write Constructor used for array types or null members
        internal void InitSerialize(Type objectType, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, SerializationBinder binder)
        {
            _objectType = objectType;
            _context = context;
            _serObjectInfoInit = serObjectInfoInit;

            if (objectType.IsArray)
            {
                InitNoMembers();
                return;
            }

            InvokeSerializationBinder(binder);

            ISurrogateSelector surrogateSelectorTemp = null;
            if (surrogateSelector != null)
            {
                _serializationSurrogate = surrogateSelector.GetSurrogate(objectType, context, out surrogateSelectorTemp);
            }

            if (_serializationSurrogate != null)
            {
                // surrogate does not have this problem since user has pass in through the BF's ctor
                _si = new SerializationInfo(objectType, converter);
                _cache = new SerObjectInfoCache(objectType);
                _isSi = true;
            }
            else if (!ReferenceEquals(objectType, Converter.s_typeofObject) && Converter.s_typeofISerializable.IsAssignableFrom(objectType))
            {
                _si = new SerializationInfo(objectType, converter);
                _cache = new SerObjectInfoCache(objectType);
                CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
                _isSi = true;
            }

            if (!_isSi)
            {
                InitMemberInfo();
                CheckTypeForwardedFrom(_cache, objectType, _binderAssemblyString);
            }
        }