GetSerializationCallbacks() public static method

public static GetSerializationCallbacks ( Type t ) : SerializationCallbacks
t System.Type
return SerializationCallbacks
示例#1
0
        void RaiseOnDeserializedEvent(object obj)
        {
            SerializationCallbacks sc = SerializationCallbacks
                                        .GetSerializationCallbacks(obj.GetType());

            sc.RaiseOnDeserialized(obj, _context);
        }
        /// <summary>Registers the object upon which events will be raised.</summary>
        /// <param name="obj">The object to register.</param>
        public void RegisterObject(object obj)
        {
            if (this.seen.Contains(obj))
            {
                return;
            }
            SerializationCallbacks sc = SerializationCallbacks.GetSerializationCallbacks(obj.GetType());

            this.seen[obj] = 1;
            sc.RaiseOnSerializing(obj, this.context);
            if (sc.HasSerializedCallbacks)
            {
                this.callbacks = (SerializationCallbacks.CallbackHandler) Delegate.Combine(this.callbacks, new SerializationCallbacks.CallbackHandler(delegate(StreamingContext ctx)
                {
                    sc.RaiseOnSerialized(obj, ctx);
                }));
            }
        }
        public void RegisterObject(object obj)
        {
            if (seen.Contains(obj))
            {
                return;
            }

            SerializationCallbacks sc = SerializationCallbacks
                                        .GetSerializationCallbacks(obj.GetType());

            seen [obj] = HashHelper.NonNullObject;
            sc.RaiseOnSerializing(obj, context);

            if (sc.HasSerializedCallbacks)
            {
                // record for later invocation
                callbacks += delegate(StreamingContext ctx)
                {
                    sc.RaiseOnSerialized(obj, ctx);
                };
            }
        }
示例#4
0
        public virtual void DoFixups()
        {
            _finalFixup = true;

            try
            {
                if (_registeredObjectsCount < _objectRecords.Count)
                {
                    throw new SerializationException("There are some fixups that refer to objects that have not been registered");
                }


                ObjectRecord last       = _lastObjectRecord;
                bool         firstCicle = true;

                // Solve al pending fixups of all objects

                ObjectRecord record = _objectRecordChain;
                while (record != null)
                {
                    bool ready = !(record.IsUnsolvedObjectReference && firstCicle);
                    if (ready)
                    {
                        ready = record.DoFixups(true, this, true);
                    }
                    if (ready)
                    {
                        ready = record.LoadData(this, _selector, _context);
                    }

                    ObjectRecord next;

                    if (ready)
                    {
                        if (record.OriginalObject is IDeserializationCallback)
                        {
                            _deserializedRecords.Add(record);
                        }

                        SerializationCallbacks sc = SerializationCallbacks
                                                    .GetSerializationCallbacks(record.OriginalObject.GetType());
                        if (sc.HasDeserializedCallbacks)
                        {
                            _onDeserializedCallbackRecords.Add(record);
                        }
                        next = record.Next;
                    }
                    else
                    {
                        // There must be an unresolved IObjectReference instance.
                        // Chain the record at the end so it is solved later

                        if ((record.ObjectInstance is IObjectReference) && !firstCicle)
                        {
                            if (record.Status == ObjectRecordStatus.ReferenceSolvingDelayed)
                            {
                                throw new SerializationException("The object with ID " + record.ObjectID + " could not be resolved");
                            }
                            else
                            {
                                record.Status = ObjectRecordStatus.ReferenceSolvingDelayed;
                            }
                        }

                        if (record != _lastObjectRecord)
                        {
                            next                   = record.Next;
                            record.Next            = null;
                            _lastObjectRecord.Next = record;
                            _lastObjectRecord      = record;
                        }
                        else
                        {
                            next = record;
                        }
                    }

                    if (record == last)
                    {
                        firstCicle = false;
                    }
                    record = next;
                }
            }
            finally
            {
                _finalFixup = false;
            }
        }
示例#5
0
 /// <summary>Performs all the recorded fixups.</summary>
 /// <exception cref="T:System.Runtime.Serialization.SerializationException">A fixup was not successfully completed. </exception>
 public virtual void DoFixups()
 {
     this._finalFixup = true;
     try
     {
         if (this._registeredObjectsCount < this._objectRecords.Count)
         {
             throw new SerializationException("There are some fixups that refer to objects that have not been registered");
         }
         ObjectRecord lastObjectRecord = this._lastObjectRecord;
         bool         flag             = true;
         ObjectRecord objectRecord2;
         for (ObjectRecord objectRecord = this._objectRecordChain; objectRecord != null; objectRecord = objectRecord2)
         {
             bool flag2 = !objectRecord.IsUnsolvedObjectReference || !flag;
             if (flag2)
             {
                 flag2 = objectRecord.DoFixups(true, this, true);
             }
             if (flag2)
             {
                 flag2 = objectRecord.LoadData(this, this._selector, this._context);
             }
             if (flag2)
             {
                 if (objectRecord.OriginalObject is IDeserializationCallback)
                 {
                     this._deserializedRecords.Add(objectRecord);
                 }
                 SerializationCallbacks serializationCallbacks = SerializationCallbacks.GetSerializationCallbacks(objectRecord.OriginalObject.GetType());
                 if (serializationCallbacks.HasDeserializedCallbacks)
                 {
                     this._onDeserializedCallbackRecords.Add(objectRecord);
                 }
                 objectRecord2 = objectRecord.Next;
             }
             else
             {
                 if (objectRecord.ObjectInstance is IObjectReference && !flag)
                 {
                     if (objectRecord.Status == ObjectRecordStatus.ReferenceSolvingDelayed)
                     {
                         throw new SerializationException("The object with ID " + objectRecord.ObjectID + " could not be resolved");
                     }
                     objectRecord.Status = ObjectRecordStatus.ReferenceSolvingDelayed;
                 }
                 if (objectRecord != this._lastObjectRecord)
                 {
                     objectRecord2               = objectRecord.Next;
                     objectRecord.Next           = null;
                     this._lastObjectRecord.Next = objectRecord;
                     this._lastObjectRecord      = objectRecord;
                 }
                 else
                 {
                     objectRecord2 = objectRecord;
                 }
             }
             if (objectRecord == lastObjectRecord)
             {
                 flag = false;
             }
         }
     }
     finally
     {
         this._finalFixup = false;
     }
 }
示例#6
0
        private void RaiseOnDeserializedEvent(object obj)
        {
            SerializationCallbacks serializationCallbacks = SerializationCallbacks.GetSerializationCallbacks(obj.GetType());

            serializationCallbacks.RaiseOnDeserialized(obj, this._context);
        }
示例#7
0
        /// <summary>Invokes the method marked with the <see cref="T:System.Runtime.Serialization.OnDeserializingAttribute" />.</summary>
        /// <param name="obj">The instance of the type that contains the method to be invoked.</param>
        public void RaiseOnDeserializingEvent(object obj)
        {
            SerializationCallbacks serializationCallbacks = SerializationCallbacks.GetSerializationCallbacks(obj.GetType());

            serializationCallbacks.RaiseOnDeserializing(obj, this._context);
        }
示例#8
0
        public virtual void DoFixups()
        {
            _finalFixup = true;

            try
            {
                if (_registeredObjectsCount < _objectRecords.Count)
                {
                    throw new SerializationException("There are some fixups that refer to objects that have not been registered");
                }


                ObjectRecord last = _lastObjectRecord;

                bool firstCycle          = true;
                bool lastCycle           = false;
                int  unresolvedCount     = 0;                   // Unresolved objects found in the current cycle
                int  lastUnresolvedCount = 0;                   // Unresolved objects before the current cycle

                // Solve al pending fixups of all objects

                ObjectRecord record = _objectRecordChain;
                while (record != null)
                {
                    // We ignore object references in the first cycle
                    bool ready = !(record.IsUnsolvedObjectReference && firstCycle);
                    if (ready)
                    {
                        ready = record.DoFixups(true, this, true);
                    }
                    if (ready)
                    {
                        ready = record.LoadData(this, _selector, _context);
                    }

                    ObjectRecord next;

                    if (ready)
                    {
                        if (record.OriginalObject is IDeserializationCallback)
                        {
                            _deserializedRecords.Add(record);
                        }

                        SerializationCallbacks sc = SerializationCallbacks
                                                    .GetSerializationCallbacks(record.OriginalObject.GetType());
                        if (sc.HasDeserializedCallbacks)
                        {
                            _onDeserializedCallbackRecords.Add(record);
                        }
                        next = record.Next;
                    }
                    else
                    {
                        // There must be an unresolved IObjectReference instance.
                        // Chain the record at the end so it is solved later

                        if ((record.ObjectInstance is IObjectReference) && !firstCycle)
                        {
                            if (record.IsUnsolvedObjectReference && lastCycle)
                            {
                                // No more chances to resolve
                                throw new SerializationException("The object with ID " + record.ObjectID + " could not be resolved");
                            }
                            else
                            {
                                unresolvedCount++;
                            }
                        }

                        if (record != _lastObjectRecord)
                        {
                            next                   = record.Next;
                            record.Next            = null;
                            _lastObjectRecord.Next = record;
                            _lastObjectRecord      = record;
                        }
                        else
                        {
                            next = record;
                        }
                    }

                    if (record == last)
                    {
                        last = _lastObjectRecord;
                        if (firstCycle)
                        {
                            firstCycle = false;
                        }
                        else
                        {
                            if (lastUnresolvedCount == unresolvedCount)
                            {
                                lastCycle = true;
                            }
                        }
                        lastUnresolvedCount = unresolvedCount;
                        unresolvedCount     = 0;
                    }
                    record = next;
                }
            }
            finally
            {
                _finalFixup = false;
            }
        }