Exemplo n.º 1
0
        internal static object CloneClassInternal(object obj, DeepCloneState state)
        {
            if (obj == null)
            {
                return(null);
            }

            var cloner = (Func <object, DeepCloneState, object>)DeepClonerCache.GetOrAddClass(obj.GetType(), t => GenerateCloner(t, true));

            // safe ojbect
            if (cloner == null)
            {
                return(obj);
            }

            // loop
            var knownRef = state.GetKnownRef(obj);

            if (knownRef != null)
            {
                return(knownRef);
            }

            return(cloner(obj, state));
        }
Exemplo n.º 2
0
        private static object CloneClassRoot(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            var cloner = (Func <object, DeepCloneState, object>)DeepClonerCache.GetOrAddClass(obj.GetType(), t => GenerateCloner(t, true));

            // null -> should return same type
            if (cloner == null)
            {
                return(obj);
            }

            return(cloner(obj, new DeepCloneState()));
        }