private void SaveSingleContainer(
            ArchiveConcurrentSerializer headerSerializer,
            byte[][] containerData,
            int id)
        {
            object            childContainer    = this._childContainers[id];
            ArchiveSerializer archiveSerializer = new ArchiveSerializer();
            SaveEntryFolder   rootFolder1       = SaveEntryFolder.CreateRootFolder();
            SaveEntryFolder   rootFolder2       = SaveEntryFolder.CreateRootFolder();
            ContainerType     containerType;

            childContainer.GetType().IsContainer(out containerType);
            ContainerSaveData containerSaveData = new ContainerSaveData((ISaveContext)this, id, childContainer, containerType);

            containerSaveData.CollectChildren();
            containerSaveData.CollectStructs();
            containerSaveData.CollectMembers();
            containerSaveData.CollectStrings();
            containerSaveData.SaveHeaderTo(rootFolder2, (IArchiveContext)headerSerializer);
            containerSaveData.SaveTo(rootFolder1, (IArchiveContext)archiveSerializer);
            headerSerializer.SerializeFolderConcurrent(rootFolder2);
            archiveSerializer.SerializeFolder(rootFolder1);
            byte[] binaryData = archiveSerializer.FinalizeAndGetBinaryData();
            containerData[id] = binaryData;
        }
        public IEnumerable <object> GetChildObjects(ISaveContext context)
        {
            List <object> collectedObjects = new List <object>();

            ContainerSaveData.GetChildObjects(context, this._typeDefinition, this._containerType, this.Target, collectedObjects);
            return((IEnumerable <object>)collectedObjects);
        }
Ejemplo n.º 3
0
 public ElementSaveData(ContainerSaveData containerSaveData, object value, int index)
     : base(containerSaveData.Context)
 {
     this.ElementValue = value;
     this.ElementIndex = index;
     if (value == null)
     {
         this.InitializeDataAsNullObject(MemberTypeId.Invalid);
     }
     else
     {
         TypeDefinitionBase typeDefinition1 = containerSaveData.Context.DefinitionContext.GetTypeDefinition(value.GetType());
         if (typeDefinition1 is TypeDefinition typeDefinition4 && !typeDefinition4.IsClassDefinition)
         {
             this.InitializeDataAsCustomStruct(MemberTypeId.Invalid, index);
         }
        private void CollectContainerObjects(ContainerType containerType, object parent)
        {
            if (this._idsOfChildContainers.ContainsKey(parent))
            {
                return;
            }
            int count = this._childContainers.Count;

            this._childContainers.Add(parent);
            this._idsOfChildContainers.Add(parent, count);
            ContainerSaveData.GetChildObjects((ISaveContext)this, this.DefinitionContext.GetContainerDefinition(parent.GetType()), containerType, parent, this._temporaryCollectedObjects);
            for (int index = 0; index < this._temporaryCollectedObjects.Count; ++index)
            {
                object temporaryCollectedObject = this._temporaryCollectedObjects[index];
                if (temporaryCollectedObject != null)
                {
                    this._objectsToIterate.Enqueue(temporaryCollectedObject);
                }
            }
            this._temporaryCollectedObjects.Clear();
        }
        public static void GetChildObjects(
            ISaveContext context,
            ContainerDefinition containerDefinition,
            ContainerType containerType,
            object target,
            List <object> collectedObjects)
        {
            if (containerDefinition.CollectObjectsMethod != null)
            {
                if (containerDefinition.HasNoChildObject)
                {
                    return;
                }
                containerDefinition.CollectObjectsMethod(target, collectedObjects);
            }
            else
            {
                switch (containerType)
                {
                case ContainerType.List:
                    IList list = (IList)target;
                    for (int index = 0; index < list.Count; ++index)
                    {
                        object childElement = list[index];
                        if (childElement != null)
                        {
                            ContainerSaveData.ProcessChildObjectElement(childElement, context, collectedObjects);
                        }
                    }
                    break;

                case ContainerType.Dictionary:
                    IDictionary dictionary = (IDictionary)target;
                    foreach (object key in (IEnumerable)dictionary.Keys)
                    {
                        ContainerSaveData.ProcessChildObjectElement(key, context, collectedObjects);
                    }
                    IEnumerator enumerator1 = dictionary.Values.GetEnumerator();
                    try
                    {
                        while (enumerator1.MoveNext())
                        {
                            object current = enumerator1.Current;
                            if (current != null)
                            {
                                ContainerSaveData.ProcessChildObjectElement(current, context, collectedObjects);
                            }
                        }
                        break;
                    }
                    finally
                    {
                        if (enumerator1 is IDisposable disposable8)
                        {
                            disposable8.Dispose();
                        }
                    }

                case ContainerType.Array:
                    Array array = (Array)target;
                    for (int index = 0; index < array.Length; ++index)
                    {
                        object childElement = array.GetValue(index);
                        if (childElement != null)
                        {
                            ContainerSaveData.ProcessChildObjectElement(childElement, context, collectedObjects);
                        }
                    }
                    break;

                case ContainerType.Queue:
                    IEnumerator enumerator2 = ((IEnumerable)target).GetEnumerator();
                    try
                    {
                        while (enumerator2.MoveNext())
                        {
                            object current = enumerator2.Current;
                            if (current != null)
                            {
                                ContainerSaveData.ProcessChildObjectElement(current, context, collectedObjects);
                            }
                        }
                        break;
                    }
                    finally
                    {
                        if (enumerator2 is IDisposable disposable9)
                        {
                            disposable9.Dispose();
                        }
                    }

                default:
                    using (IEnumerator <object> enumerator3 = ContainerSaveData.GetChildElements(containerType, target).GetEnumerator())
                    {
                        while (enumerator3.MoveNext())
                        {
                            ContainerSaveData.ProcessChildObjectElement(enumerator3.Current, context, collectedObjects);
                        }
                        break;
                    }
                }
            }
        }
 public IEnumerable <object> GetChildElements() => ContainerSaveData.GetChildElements(this._containerType, this.Target);