Example #1
0
        private static object CloneClassRoot(object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            // we can receive an poco objects which is faster to copy in shallow way if possible
            var type = obj.GetType();

            // 200ms
            if (DeepClonerSafeTypes.CanNotDeepCopyClass(type))
            {
                return(ShallowObjectCloner.CloneObject(obj));
            }
            // 350ms
            var cloner = (Func <object, DeepCloneState, object>)DeepClonerCache.GetOrAddClass(type, t => GenerateCloner(t, true));

            if (cloner == null)
            {
                return(obj);
            }

            // 200ms
            return(cloner(obj, new DeepCloneState()));
        }
        private static object CloneClassRoot(object obj)
        {
            if (obj == null)
            {
                return(null);
            }
            Type type = obj.GetType();

            if (DeepClonerSafeTypes.CanNotDeepCopyClass(type))
            {
                return(ShallowObjectCloner.CloneObject(obj));
            }
            Func <object, DeepCloneState, object> func = (Func <object, DeepCloneState, object>)DeepClonerCache.GetOrAddClass(type, (Type t) => GenerateCloner(t, true));

            if (func == null)
            {
                return(obj);
            }
            return(func(obj, new DeepCloneState()));
        }