System.Runtime.Serialization.ObjectRecord.LoadData C# (CSharp) Method

LoadData() public method

public LoadData ( ObjectManager manager, ISurrogateSelector selector, StreamingContext context ) : bool
manager ObjectManager
selector ISurrogateSelector
context StreamingContext
return bool
        public bool LoadData(ObjectManager manager, ISurrogateSelector selector, StreamingContext context)
        {
            if (Info != null) {
                if (Surrogate != null) {
                    object new_obj = Surrogate.SetObjectData(ObjectInstance, Info, context, SurrogateSelector);
                    if (new_obj != null)
                        ObjectInstance = new_obj;
                    Status = ObjectRecordStatus.ReferenceSolved;
                } else if (ObjectInstance is ISerializable) {
                    object[] pars = new object[] { Info, context };
                    ConstructorInfo con = FindConstructor();
                    if (con == null) throw new SerializationException("The constructor to deserialize an object of type " + ObjectInstance.GetType().FullName + " was not found.");
                    con.Invoke(ObjectInstance, pars);
                } else {
                    throw new SerializationException("No surrogate selector was found for type " + ObjectInstance.GetType().FullName);
                }

                Info = null;
            }

            if (ObjectInstance is IObjectReference && Status != ObjectRecordStatus.ReferenceSolved) {
                try {
                    ObjectInstance = ((IObjectReference)ObjectInstance).GetRealObject(context);
                    int n = 100;
                    while (ObjectInstance is IObjectReference && n > 0) {
                        object ob = ((IObjectReference)ObjectInstance).GetRealObject(context);
                        if (ob == ObjectInstance)
                            break;
                        ObjectInstance = ob;
                        n--;
                    }
                    if (n == 0)
                        throw new SerializationException("The implementation of the IObjectReference interface returns too many nested references to other objects that implement IObjectReference.");

                    Status = ObjectRecordStatus.ReferenceSolved;
                } catch (NullReferenceException) {
                    // Give a second chance
                    return false;
                }
            }

            if (Member != null) {
                // If this object is a value object embedded in another object, the parent
                // object must be updated

                ObjectRecord containerRecord = manager.GetObjectRecord(IdOfContainingObj);
                containerRecord.SetMemberValue(manager, Member, ObjectInstance);
            } else if (ArrayIndex != null) {
                ObjectRecord containerRecord = manager.GetObjectRecord(IdOfContainingObj);
                containerRecord.SetArrayValue(manager, ObjectInstance, ArrayIndex);
            }

            return true;
        }

Usage Example

コード例 #1
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;
     }
 }
All Usage Examples Of System.Runtime.Serialization.ObjectRecord::LoadData