The Evil Undercover Twin (aka
Martin's Deep Clone)
using System;
using System.Runtime.Serialization ;
using System.IO;
using System.Reflection;
namespace DemoControl
{
/// <summary>
/// Summary description for fred.
/// </summary>
[Serializable]
public class fred : ICloneable
{
public string name;
public fred()
{
//
// TODO: Add constructor logic here
//
}
public object Clone()
{
MemoryStream mSTream = null;
try
{
mSTream = new MemoryStream();
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter myBinaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
myBinaryFormatter.Serialize(mSTream, this);
mSTream.Position = 0;
return myBinaryFormatter.Deserialize(mSTream);
}
finally
{
mSTream.Close();
}
}
}
}