コード例 #1
0
ファイル: objectmanager.cs プロジェクト: ArildF/masters
 /// <include file='doc\ObjectManager.uex' path='docs/doc[@for="ObjectManager.RemoveOnDeserialization"]/*' />
 internal virtual void RemoveOnDeserialization(DeserializationEventHandler handler) {
     m_onDeserializationHandler = (DeserializationEventHandler)Delegate.Remove(m_onDeserializationHandler, handler);
 }
コード例 #2
0
ファイル: objectmanager.cs プロジェクト: ArildF/masters
        /// <include file='doc\ObjectManager.uex' path='docs/doc[@for="ObjectManager.RegisterObject3"]/*' />
        public void RegisterObject(Object obj, long objectID, SerializationInfo info, long idOfContainingObj, MemberInfo member, int[] arrayIndex) {
            ObjectHolder temp;
            ISerializationSurrogate surrogate = null;
            ISurrogateSelector useless;
    
            if (obj==null) {
                throw new ArgumentNullException("obj");
            }
            if (objectID<=0) {
                throw new ArgumentOutOfRangeException("objectID", Environment.GetResourceString("ArgumentOutOfRange_ObjectID"));
            }

            if (member!=null && !(member is RuntimeFieldInfo) && !(member is SerializationFieldInfo)) {
                throw new SerializationException(Environment.GetResourceString("Serialization_UnknownMemberInfo"));
            }
    
            if (m_selector != null)
            {
                Type selectorType=null;
                if (CanCallGetType(obj)) {
                    selectorType = obj.GetType();
                } else {
                    selectorType = typeof(MarshalByRefObject);
                }

                BCLDebug.Trace("SER", "[ObjectManager.RegisterObject]ID: ", objectID, "\tType: ", selectorType, "\tValue: ", obj);
    
                //If we need a surrogate for this object, lets find it now.
                surrogate = m_selector.GetSurrogate(selectorType, m_context, out useless);
            }

            //The object is interested in DeserializationEvents so lets register it.
            if (obj is IDeserializationCallback) {
                DeserializationEventHandler d = new DeserializationEventHandler(((IDeserializationCallback)obj).OnDeserialization);
                AddOnDeserialization(d);
            }
    
            temp = FindObjectHolder(objectID);
    
            //This is the first time which we've seen the object, we need to create a new holder.
            if (temp==null) { 
                BCLDebug.Trace("SER", "[ObjectManager.RegisterObject]Adding a new object holder for ", objectID);
                //Formatter developers may cache and reuse arrayIndex in their code.
                //So that we don't get bitten by this, take a copy up front.
                int [] arrayTemp=null;
                if (arrayIndex!=null) {
                    arrayTemp = (int[])arrayIndex.Clone();
                }
                temp = new ObjectHolder(obj, objectID, info, surrogate, idOfContainingObj, (FieldInfo)member, arrayTemp);
                AddObjectHolder(temp);
                if (temp.RequiresDelayedFixup) {
                    SpecialFixupObjects.Add(temp);   
                }
                return;
            } 
            
            //If the object isn't null, we've registered this before.  Not good.
            if (temp.ObjectValue!=null) {
                throw new SerializationException(Environment.GetResourceString("Serialization_RegisterTwice"));
            }
            
            //Complete the data in the ObjectHolder
            temp.UpdateData(obj, info, surrogate, idOfContainingObj, (FieldInfo)member, arrayIndex, this);

            // The following case will only be true when somebody has registered a fixup on an object before
            // registering the object itself.  I don't believe that most well-behaved formatters will do this,
            // but we need to allow it anyway.  We will walk the list of fixups which have been recorded on 
            // the new object and fix those that we can.  Because the user could still register later fixups
            // on this object, we won't call any implementations of ISerializable now.  If that's required,
            // it will have to be handled by the code in DoFixups.
            // README README: We have to do the UpdateData before 
            if (temp.DirectlyDependentObjects>0) {
                CompleteObject(temp, false);
            }

            if (temp.RequiresDelayedFixup) {
                BCLDebug.Trace("SER", "[ObjectManager.RegisterObject]Tracking incomplete objref for element: ", temp.m_id);
                SpecialFixupObjects.Add(temp);   
            } 

            if (!(temp.IsIncompleteObjectReference)) {
                //Here's where things get tricky.  If this isn't an instance of IObjectReference, we need to walk it's fixup 
                //chain and decrement the counters on anything that has reached 0.  Once we've notified all of the dependencies,
                //we can simply clear the list of dependent objects.
                BCLDebug.Trace("SER", "[ObjectManager.RegisterObject]Calling DoNewlyRegisteredObjectFixups for element: ", temp.m_id);
                DoNewlyRegisteredObjectFixups(temp);
                temp.DependentObjects=null;
            }
            BCLDebug.Trace("SER", "[ObjectManager.RegisterObject]Exiting.");
        }
コード例 #3
0
ファイル: objectmanager.cs プロジェクト: ArildF/masters
 /// <include file='doc\ObjectManager.uex' path='docs/doc[@for="ObjectManager.AddOnDeserialization"]/*' />
 internal virtual void AddOnDeserialization(DeserializationEventHandler handler) {
     m_onDeserializationHandler = (DeserializationEventHandler)Delegate.Combine(m_onDeserializationHandler, handler);
 }
コード例 #4
0
 // Token: 0x06005164 RID: 20836 RVA: 0x0011DAC3 File Offset: 0x0011BCC3
 internal virtual void AddOnDeserialization(DeserializationEventHandler handler)
 {
     this.m_onDeserializationHandler = (DeserializationEventHandler)Delegate.Combine(this.m_onDeserializationHandler, handler);
 }
コード例 #5
0
 // Token: 0x06005165 RID: 20837 RVA: 0x0011DADC File Offset: 0x0011BCDC
 internal virtual void RemoveOnDeserialization(DeserializationEventHandler handler)
 {
     this.m_onDeserializationHandler = (DeserializationEventHandler)Delegate.Remove(this.m_onDeserializationHandler, handler);
 }
コード例 #6
0
        public void RegisterObject(object obj, long objectID, SerializationInfo info, long idOfContainingObj, MemberInfo member, int[] arrayIndex)
        {
            if (obj == null)
            {
                throw new ArgumentNullException("obj");
            }
            if (objectID <= 0L)
            {
                throw new ArgumentOutOfRangeException("objectID", Environment.GetResourceString("ArgumentOutOfRange_ObjectID"));
            }
            if (member != null && !(member is RuntimeFieldInfo) && !(member is SerializationFieldInfo))
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_UnknownMemberInfo"));
            }
            ISerializationSurrogate surrogate = null;

            if (this.m_selector != null)
            {
                Type type;
                if (this.CanCallGetType(obj))
                {
                    type = obj.GetType();
                }
                else
                {
                    type = typeof(MarshalByRefObject);
                }
                ISurrogateSelector surrogateSelector;
                surrogate = this.m_selector.GetSurrogate(type, this.m_context, out surrogateSelector);
            }
            if (obj is IDeserializationCallback)
            {
                DeserializationEventHandler handler = new DeserializationEventHandler(((IDeserializationCallback)obj).OnDeserialization);
                this.AddOnDeserialization(handler);
            }
            if (arrayIndex != null)
            {
                arrayIndex = (int[])arrayIndex.Clone();
            }
            ObjectHolder objectHolder = this.FindObjectHolder(objectID);

            if (objectHolder == null)
            {
                objectHolder = new ObjectHolder(obj, objectID, info, surrogate, idOfContainingObj, (FieldInfo)member, arrayIndex);
                this.AddObjectHolder(objectHolder);
                if (objectHolder.RequiresDelayedFixup)
                {
                    this.SpecialFixupObjects.Add(objectHolder);
                }
                this.AddOnDeserialized(obj);
                return;
            }
            if (objectHolder.ObjectValue != null)
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_RegisterTwice"));
            }
            objectHolder.UpdateData(obj, info, surrogate, idOfContainingObj, (FieldInfo)member, arrayIndex, this);
            if (objectHolder.DirectlyDependentObjects > 0)
            {
                this.CompleteObject(objectHolder, false);
            }
            if (objectHolder.RequiresDelayedFixup)
            {
                this.SpecialFixupObjects.Add(objectHolder);
            }
            if (objectHolder.CompletelyFixed)
            {
                this.DoNewlyRegisteredObjectFixups(objectHolder);
                objectHolder.DependentObjects = null;
            }
            if (objectHolder.TotalDependentObjects > 0)
            {
                this.AddOnDeserialized(obj);
                return;
            }
            this.RaiseOnDeserializedEvent(obj);
        }
コード例 #7
0
ファイル: ObjectManager.cs プロジェクト: dotnet/corefx
        public void RegisterObject(object obj, long objectID, SerializationInfo info, long idOfContainingObj, MemberInfo member, int[] arrayIndex)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            if (objectID <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(objectID), SR.ArgumentOutOfRange_ObjectID);
            }
            if (member != null && !(member is FieldInfo))
            {
                throw new SerializationException(SR.Serialization_UnknownMemberInfo);
            }

            ObjectHolder temp;
            ISerializationSurrogate surrogate = null;
            ISurrogateSelector useless;

            if (_selector != null)
            {
                Type selectorType = CanCallGetType(obj) ?
                    obj.GetType() :
                    typeof(MarshalByRefObject);

                //If we need a surrogate for this object, lets find it now.
                surrogate = _selector.GetSurrogate(selectorType, _context, out useless);
            }

            //The object is interested in DeserializationEvents so lets register it.
            if (obj is IDeserializationCallback)
            {
                DeserializationEventHandler d = new DeserializationEventHandler(((IDeserializationCallback)obj).OnDeserialization);
                AddOnDeserialization(d);
            }

            //Formatter developers may cache and reuse arrayIndex in their code.
            //So that we don't get bitten by this, take a copy up front.
            if (arrayIndex != null)
            {
                arrayIndex = (int[])arrayIndex.Clone();
            }

            //This is the first time which we've seen the object, we need to create a new holder.
            temp = FindObjectHolder(objectID);
            if (temp == null)
            {
                temp = new ObjectHolder(obj, objectID, info, surrogate, idOfContainingObj, (FieldInfo)member, arrayIndex);
                AddObjectHolder(temp);
                if (temp.RequiresDelayedFixup)
                {
                    SpecialFixupObjects.Add(temp);
                }

                // We cannot compute whether this has any fixups required or not
                AddOnDeserialized(obj);
                return;
            }

            //If the object isn't null, we've registered this before.  Not good.
            if (temp.ObjectValue != null)
            {
                throw new SerializationException(SR.Serialization_RegisterTwice);
            }

            //Complete the data in the ObjectHolder
            temp.UpdateData(obj, info, surrogate, idOfContainingObj, (FieldInfo)member, arrayIndex, this);

            // The following case will only be true when somebody has registered a fixup on an object before
            // registering the object itself.  I don't believe that most well-behaved formatters will do this,
            // but we need to allow it anyway.  We will walk the list of fixups which have been recorded on 
            // the new object and fix those that we can.  Because the user could still register later fixups
            // on this object, we won't call any implementations of ISerializable now.  If that's required,
            // it will have to be handled by the code in DoFixups.
            // README README: We have to do the UpdateData before 
            if (temp.DirectlyDependentObjects > 0)
            {
                CompleteObject(temp, false);
            }

            if (temp.RequiresDelayedFixup)
            {
                SpecialFixupObjects.Add(temp);
            }

            if (temp.CompletelyFixed)
            {
                //Here's where things get tricky.  If this isn't an instance of IObjectReference, we need to walk it's fixup 
                //chain and decrement the counters on anything that has reached 0.  Once we've notified all of the dependencies,
                //we can simply clear the list of dependent objects.
                DoNewlyRegisteredObjectFixups(temp);
                temp.DependentObjects = null;
            }

            //Register the OnDeserialized methods to be invoked after deserialization is complete
            if (temp.TotalDependentObjects > 0)
            {
                AddOnDeserialized(obj);
            }
            else
            {
                RaiseOnDeserializedEvent(obj);
            }
        }
コード例 #8
0
 public void RegisterObject(object obj, long objectID, SerializationInfo info, long idOfContainingObj, MemberInfo member, int[] arrayIndex)
 {
     if (obj == null)
     {
         throw new ArgumentNullException("obj");
     }
     if (objectID <= 0L)
     {
         throw new ArgumentOutOfRangeException("objectID", Environment.GetResourceString("ArgumentOutOfRange_ObjectID"));
     }
     if (((member != null) && !(member is RuntimeFieldInfo)) && !(member is SerializationFieldInfo))
     {
         throw new SerializationException(Environment.GetResourceString("Serialization_UnknownMemberInfo"));
     }
     ISerializationSurrogate surrogate = null;
     if (this.m_selector != null)
     {
         ISurrogateSelector selector;
         Type type = null;
         if (this.CanCallGetType(obj))
         {
             type = obj.GetType();
         }
         else
         {
             type = typeof(MarshalByRefObject);
         }
         surrogate = this.m_selector.GetSurrogate(type, this.m_context, out selector);
     }
     if (obj is IDeserializationCallback)
     {
         IDeserializationCallback callback1 = (IDeserializationCallback) obj;
         DeserializationEventHandler handler = new DeserializationEventHandler(callback1.OnDeserialization);
         this.AddOnDeserialization(handler);
     }
     if (arrayIndex != null)
     {
         arrayIndex = (int[]) arrayIndex.Clone();
     }
     ObjectHolder holder = this.FindObjectHolder(objectID);
     if (holder == null)
     {
         holder = new ObjectHolder(obj, objectID, info, surrogate, idOfContainingObj, (FieldInfo) member, arrayIndex);
         this.AddObjectHolder(holder);
         if (holder.RequiresDelayedFixup)
         {
             this.SpecialFixupObjects.Add(holder);
         }
         this.AddOnDeserialized(obj);
     }
     else
     {
         if (holder.ObjectValue != null)
         {
             throw new SerializationException(Environment.GetResourceString("Serialization_RegisterTwice"));
         }
         holder.UpdateData(obj, info, surrogate, idOfContainingObj, (FieldInfo) member, arrayIndex, this);
         if (holder.DirectlyDependentObjects > 0)
         {
             this.CompleteObject(holder, false);
         }
         if (holder.RequiresDelayedFixup)
         {
             this.SpecialFixupObjects.Add(holder);
         }
         if (holder.CompletelyFixed)
         {
             this.DoNewlyRegisteredObjectFixups(holder);
             holder.DependentObjects = null;
         }
         if (holder.TotalDependentObjects > 0)
         {
             this.AddOnDeserialized(obj);
         }
         else
         {
             this.RaiseOnDeserializedEvent(obj);
         }
     }
 }
コード例 #9
0
 internal virtual void RemoveOnDeserialization(DeserializationEventHandler handler)
 {
     this.m_onDeserializationHandler = this.m_onDeserializationHandler - handler;
 }
コード例 #10
0
 internal virtual void AddOnDeserialization(DeserializationEventHandler handler)
 {
     this.m_onDeserializationHandler = this.m_onDeserializationHandler + handler;
 }