Beispiel #1
0
        protected override void OnCopyTo(Resource r, Duality.Cloning.CloneProvider provider)
        {
            base.OnCopyTo(r, provider);
            Prefab c = r as Prefab;

            c.objTree = provider.RequestObjectClone(this.objTree);
        }
Beispiel #2
0
        protected override void OnCopyTo(Component target, Duality.Cloning.CloneProvider provider)
        {
            base.OnCopyTo(target, provider);
            SoundEmitter c = target as SoundEmitter;

            c.sources = this.sources == null ? null : this.sources.Select(s => provider.RequestObjectClone(s)).ToList();
        }
Beispiel #3
0
 public static void DeepCopyTo <T>(this T baseObj, T targetObj, CloneProviderContext context = null)
 {
     CloneProvider.DeepCopyTo <T>(baseObj, targetObj, context);
 }
Beispiel #4
0
 public static T DeepClone <T>(this T baseObj, CloneProviderContext context = null)
 {
     return(CloneProvider.DeepClone <T>(baseObj, context));
 }
Beispiel #5
0
        internal static void PerformReflectionFallback <T>(string copyMethodName, T baseObj, T targetObj, CloneProvider provider)
        {
            if (copyMethodName == null)
            {
                throw new ArgumentNullException("copyMethodName");
            }
            if (baseObj == null)
            {
                throw new ArgumentNullException("baseObj");
            }
            if (targetObj == null)
            {
                throw new ArgumentNullException("targetObj");
            }

            // Use explicit unwrapping: Only unwrap (deep-copy) collection types, shallow-copy others.
            provider.ExplicitUnwrap.Add(typeof(System.Collections.ICollection));

            // Travel up the inheritance hierarchy
            // Don't fallback for types from the Duality Assembly. Those are required to do explicit copying.
            Type curType = baseObj.GetType();

            while (curType.Assembly != typeof(DualityApp).Assembly && typeof(T).IsAssignableFrom(curType))
            {
                // Retrieve OnCopyTo method, if declared in this specific class (local override)
                MethodInfo localOnCopyTo = curType.GetMethod(
                    copyMethodName,
                    BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                    null,
                    new[] { typeof(T), typeof(CloneProvider) },
                    null);
                // Apply default behaviour to any class that doesn't have its own OnCopyTo override
                if (localOnCopyTo == null)
                {
                    provider.CopyObjectTo(
                        baseObj,
                        targetObj,
                        curType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
                }

                curType = curType.BaseType;
            }

            // Deactivate explicit unwrapping again
            provider.ExplicitUnwrap.Remove(typeof(System.Collections.ICollection));
        }
Beispiel #6
0
        public static T DeepClone <T>(T baseObj, CloneProviderContext context = null)
        {
            CloneProvider provider = new CloneProvider(context);

            return((T)provider.RequestObjectClone(baseObj));
        }