Beispiel #1
0
        private static UnloadableObjectRemover GetYamlProxyRemover()
        {
            var yamlProxyRemover = instanceTLS;

            if (yamlProxyRemover == null)
            {
                instanceTLS = yamlProxyRemover = new UnloadableObjectRemover();
            }
            return(yamlProxyRemover);
        }
Beispiel #2
0
        /// <summary>
        /// Clones the current value of this cloner with the specified new shadow registry (optional)
        /// </summary>
        /// <param name="idRemapping">A dictionary containing the remapping of <see cref="IIdentifiable.Id"/> if <see cref="AssetClonerFlags.GenerateNewIdsForIdentifiableObjects"/> has been passed to the cloner.</param>
        /// <returns>A clone of the value associated with this cloner.</returns>
        private object Clone([NotNull] out Dictionary <Guid, Guid> idRemapping)
        {
            if (streamOrValueType is Stream stream)
            {
                stream.Position = 0;
                var reader = new BinarySerializationReader(stream);
                reader.Context.SerializerSelector = ClonerSelector;
                reader.Context.Set(InvariantObjectListProperty, invariantObjects);
                reader.Context.Set(ContentSerializerContext.SerializeAttachedReferenceProperty, GenerateContentSerializerFlags(flags));
                if (externalIdentifiables != null)
                {
                    if ((flags & AssetClonerFlags.ClearExternalReferences) != 0)
                    {
                        externalIdentifiables.Clear();
                    }

                    reader.Context.Set(MemberSerializer.ExternalIdentifiables, externalIdentifiables);
                }
                if ((flags & AssetClonerFlags.KeepReferences) != 0)
                {
                    reader.Context.Set(ReferenceSerializer.CloneReferences, cloneReferences);
                }
                reader.Context.Set(MemberSerializer.ObjectDeserializeCallback, OnObjectDeserialized);
                object newObject = null;
                reader.SerializeExtended(ref newObject, ArchiveMode.Deserialize);

                if ((flags & AssetClonerFlags.RemoveUnloadableObjects) != 0)
                {
                    UnloadableObjectRemover.Run(newObject);
                }

                idRemapping = cloningIdRemapping;
                return(newObject);
            }
            // Else this is a value type, so it is cloned automatically
            idRemapping = new Dictionary <Guid, Guid>();
            return(streamOrValueType);
        }