Esempio n. 1
0
 private void OnObjectDeserialized(int i, object newObject)
 {
     if (objectReferences != null && newObject != null)
     {
         var previousObject = objectReferences[i];
         ShadowObject.CopyDynamicProperties(previousObject, newObject);
         if ((flags & AssetClonerFlags.RemoveOverrides) != 0)
         {
             Override.RemoveFrom(newObject);
         }
     }
 }
Esempio n. 2
0
        private void OnObjectDeserialized(int i, object newObject)
        {
            if (objectReferences != null && newObject != null)
            {
                var previousObject = objectReferences[i];

                //// If the object is an attached reference, there is no need to copy the shadow object
                //if (AttachedReferenceManager.GetAttachedReference(previousObject) != null)
                //{
                //    return;
                //}

                ShadowObject.Copy(previousObject, newObject);
                if ((flags & AssetClonerFlags.RemoveOverrides) != 0)
                {
                    Override.RemoveFrom(newObject);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Clones the current value of this cloner with the specified new shadow registry (optional)
        /// </summary>
        /// <returns>A clone of the value associated with this cloner.</returns>
        private object Clone()
        {
            var stream = streamOrValueType as Stream;

            if (stream != null)
            {
                stream.Position = 0;
                var reader = new BinarySerializationReader(stream);
                reader.Context.SerializerSelector = ClonerSelector;
                var refFlag = (flags & AssetClonerFlags.ReferenceAsNull) != 0
                    ? ContentSerializerContext.AttachedReferenceSerialization.AsNull
                    : ContentSerializerContext.AttachedReferenceSerialization.AsSerializableVersion;
                reader.Context.Set(InvariantObjectListProperty, invariantObjects);
                reader.Context.Set(ContentSerializerContext.SerializeAttachedReferenceProperty, refFlag);
                object newObject = null;
                reader.SerializeExtended(ref newObject, ArchiveMode.Deserialize);

                // If there are any references, we would like to copy all dynamic properties from ShadowObject to the new instances
                if (objectReferences != null)
                {
                    var newObjectReferences = reader.Context.Get(MemberSerializer.ObjectDeserializeReferences);
                    foreach (var objRef in objectReferences)
                    {
                        var innerObject    = objRef.Key;
                        var newInnerObject = newObjectReferences[objRef.Value];
                        // Copy only when objects are non-null
                        if (innerObject != null && newInnerObject != null)
                        {
                            ShadowObject.CopyDynamicProperties(innerObject, newInnerObject);
                            if ((flags & AssetClonerFlags.RemoveOverrides) != 0)
                            {
                                Override.RemoveFrom(newInnerObject);
                            }
                        }
                    }
                }

                return(newObject);
            }
            // Else this is a value type, so it is cloned automatically
            return(streamOrValueType);
        }