.NET Version of Clone

One of my peers wrote this commenting on how much easier it was to clone in .NET vs Java.

Within your entity/object:

        public object Clone()
        {
            object clone;
            using (MemoryStream memory = new MemoryStream())
            {
                BinaryFormatter formater = new BinaryFormatter();
                formater.Serialize(memory, this);
                memory.Seek(0, SeekOrigin.Begin);
                clone = formater.Deserialize(memory);
                return clone;
            }
        }
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s