private static Dictionary <AssetViewModel, List <ItemToReload> > PrepareAssemblyReloading(SessionViewModel session, UnloadingVisitor visitor, IUndoRedoService actionService)
        {
            var assetItemsToReload = new Dictionary <AssetViewModel, List <ItemToReload> >();

            // Serialize old objects from unloaded assemblies to Yaml streams
            foreach (var asset in session.LocalPackages.SelectMany(x => x.Assets))
            {
                // Asset has no quantum graph (eg. text asset), let's skip it
                if (asset.PropertyGraph == null)
                {
                    continue;
                }

                // Generate missing ids for safetly
                AssetCollectionItemIdHelper.GenerateMissingItemIds(asset.Asset);

                // Serialize objects with types to unload to Yaml
                // Objects that were already IUnloadable will also be included
                var rootNode      = session.AssetNodeContainer.GetNode(asset.Asset);
                var itemsToReload = visitor.Run(asset.PropertyGraph);

                if (itemsToReload.Count > 0)
                {
                    // We apply changes in opposite visit order so that indices remains valid when we remove objects while iterating
                    for (int index = itemsToReload.Count - 1; index >= 0; index--)
                    {
                        var itemToReload = itemsToReload[index];

                        // Transform path to Quantum
                        itemToReload.GraphPath = GraphNodePath.From(rootNode, itemToReload.Path, out itemToReload.GraphPathIndex);

                        // Remove (collections) or replace nodes with null (members) so that we can unload assemblies
                        ClearNode(actionService, asset, itemToReload);
                    }

                    // Add to list of items to reload for PostAssemblyReloading
                    assetItemsToReload.Add(asset, new List <ItemToReload>(itemsToReload));
                }
            }

            return(assetItemsToReload);
        }
            protected override bool ProcessObject(object obj, Type expectedType)
            {
                // TODO: More advanced checks if IUnloadable is supposed to be a type from the unloaded assembly (this would avoid processing unecessary IUnloadable)
                if (obj != null && (UnloadedAssemblies.Contains(obj.GetType().Assembly) || obj is IUnloadable))
                {
                    NodeIndex index;
                    var       settings = new SerializerContextSettings(Log);
                    var       path     = GraphNodePath.From(propertyGraph.RootNode, CurrentPath, out index);

                    var overrides = AssetPropertyGraph.GenerateOverridesForSerialization(path.GetNode());
                    overrides = RemoveFirstIndexInYamlPath(overrides, index);
                    if (overrides != null)
                    {
                        settings.Properties.Add(AssetObjectSerializerBackend.OverrideDictionaryKey, overrides);
                    }

                    var objectReferences = propertyGraph.GenerateObjectReferencesForSerialization(path.GetNode());
                    objectReferences = RemoveFirstIndexInYamlPath(objectReferences, index);
                    if (objectReferences != null)
                    {
                        settings.Properties.Add(AssetObjectSerializerBackend.ObjectReferencesKey, objectReferences);
                    }

                    var parsingEvents = new List <ParsingEvent>();
                    AssetYamlSerializer.Default.Serialize(new ParsingEventListEmitter(parsingEvents), obj, expectedType, settings);

                    // Buid parent path
                    var parentPath = CurrentPath.Clone();
                    parentPath.Pop();

                    ItemsToReload.Add(new ItemToReload(parentPath, CurrentPath.Clone(), parsingEvents, expectedType));

                    // Don't recurse inside
                    return(true);
                }
                return(false);
            }