System.Runtime.Serialization.ObjectHolder.UpdateData C# (CSharp) Method

UpdateData() private method

Update the data in the object holder. This should be called when the object is finally registered. Presumably the ObjectHolder was created to track some dependencies or preregistered fixups and we now need to actually record the object and other associated data. We take this opportunity to set the flags so that we can do some faster processing in the future.
private UpdateData ( object obj, SerializationInfo info, ISerializationSurrogate surrogate, long idOfContainer, FieldInfo field, int arrayIndex, ObjectManager manager ) : void
obj object The object being held by this object holder. (This should no longer be null).
info SerializationInfo
surrogate ISerializationSurrogate The surrogate handling this object. May be null.
idOfContainer long The id of the object containing this one if this is a valuetype.
field System.Reflection.FieldInfo The SerializationInfo associated with this object, only required if we're doing delayed fixups.
arrayIndex int
manager ObjectManager the ObjectManager being used to track these ObjectHolders.
return void
        internal void UpdateData(
            object obj, SerializationInfo info, ISerializationSurrogate surrogate, long idOfContainer, 
            FieldInfo field, int[] arrayIndex, ObjectManager manager)
        {
            Debug.Assert(obj != null, "obj!=null");
            Debug.Assert(_id > 0, "m_id>0");

            //Record the fields that we can.
            SetObjectValue(obj, manager);
            _serInfo = info;
            _surrogate = surrogate;

            if (idOfContainer != 0 && ((field != null && field.FieldType.IsValueType) || arrayIndex != null))
            {
                if (idOfContainer == _id)
                {
                    throw new SerializationException(SR.Serialization_ParentChildIdentical);
                }
                _valueFixup = new ValueTypeFixupInfo(idOfContainer, field, arrayIndex);
            }

            SetFlags();

            if (RequiresValueTypeFixup)
            {
                UpdateDescendentDependencyChain(_missingElementsRemaining, manager);
            }
        }

Usage Example

コード例 #1
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 != (MemberInfo)null && !(member is RuntimeFieldInfo) && !(member is SerializationFieldInfo))
            {
                throw new SerializationException(Environment.GetResourceString("Serialization_UnknownMemberInfo"));
            }
            ISerializationSurrogate surrogate = (ISerializationSurrogate)null;

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

            if (objectHolder == null)
            {
                ObjectHolder 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 (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 = (LongList)null;
                }
                if (objectHolder.TotalDependentObjects > 0)
                {
                    this.AddOnDeserialized(obj);
                }
                else
                {
                    this.RaiseOnDeserializedEvent(obj);
                }
            }
        }