﻿namespace DevelopmentInProgress.DipCore
{
    /// <summary>
    /// Provides a DeepClone extension method.
    /// </summary>
    public static class CloneExtension
    {
        /// <summary>
        /// Performs a deep clone of an object by serializing it and then deserializing again.
        /// </summary>
        /// <typeparam name="T">The type of the object to clone.</typeparam>
        /// <param name="source">The object to clone.</param>
        /// <returns>A deep clone of the object.</returns>
        public static T DeepClone<T>(this T source)
        {
            var serialised = Serializer.SerializeToXml(source);
            var deserialised = Serializer.DeserializeXml<T>(serialised);
            return deserialised;
        }
    }
}
