Esempio n. 1
0
        /// <summary>
        /// Creates a copy of the object.
        /// </summary>
        /// <param name="instance">The object to be copied.</param>
        /// <returns>A deep copy of the object.</returns>
        public static object Copy(this object instance)
        {
            if (instance == null)
            {
                return(null);
            }

            var copy = InstanceCreator.GetInstance(instance.GetType());

            Copy(instance, copy);
            //var ser1 = Serialize(instance);
            //var ser2 = Serialize(copy);
            //if (!CompareMemoryStreams(ser1, ser2))
            //{
            //    var co = new CompareObjects();
            //    co.CompareChildren = true;
            //    co.ComparePrivateFields = true;
            //    co.ComparePrivateProperties = true;
            //    co.Compare(instance, copy);
            //    throw new InvalidOperationException(co.DifferencesString);
            //}
            return(copy);
        }