code

public T Clone<T>(T RealObject)
{
    using (System.IO.Stream objectStream = new System.IO.MemoryStream())
    {
        System.Runtime.Serialization.IFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
        formatter.Serialize(objectStream, RealObject);
        objectStream.Seek(0, System.IO.SeekOrigin.Begin);
        return (T)formatter.Deserialize(objectStream);
    }
}  

你可能感兴趣的:(code)