File Stream C#

//--------------------------------------------------------------------------
// 
//  Copyright (c) Microsoft Corporation.  All rights reserved. 
// 
//  File: Utilities.cs
//
//--------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace ParallelMorph
{
    /// Helper utilities.
    public static class Utilities
    {
        /// Deep clones a serializable object.
        /// Specifies the type of the object to be cloned.
        /// The source object to be cloned.
        /// The generated deep clone.
        public static T DeepClone(T source) where T : class
        {
            using (MemoryStream ms = new MemoryStream())
            {
                var formatter = new BinaryFormatter();
                formatter.Serialize(ms, source);
                ms.Position = 0;
                return (T)formatter.Deserialize(ms);
            }
        }
    }
}