<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shawson&#039;s Code Blog &#187; deep copy</title>
	<atom:link href="http://codeblog.shawson.co.uk/tag/deep-copy/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeblog.shawson.co.uk</link>
	<description>development notes for my failing memory</description>
	<lastBuildDate>Tue, 15 May 2012 15:22:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Deep Copy Array/ Collection/ etc using serialization</title>
		<link>http://codeblog.shawson.co.uk/deep-copy-array-collection-etc/</link>
		<comments>http://codeblog.shawson.co.uk/deep-copy-array-collection-etc/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 10:28:41 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#.net]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[collection]]></category>
		<category><![CDATA[deep copy]]></category>
		<category><![CDATA[serialise]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=358</guid>
		<description><![CDATA[A useful snippet of code I used in a web services project a while ago which i just stumbled back across recently- allows you to make a deep copy of an array, where you would normally get a shallow copy, stopping you from manipulating it independently from the source. This gives you a completely fresh [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/a-complete-list-of-net-serializers-in-3-5/' rel='bookmark' title='A complete list of .NET Serializers in 3.5'>A complete list of .NET Serializers in 3.5</a></li>
<li><a href='http://codeblog.shawson.co.uk/adding-javascript-unit-testing-compression-to-your-build/' rel='bookmark' title='Adding Javascript Unit Testing/ Compression to your MSBuild'>Adding Javascript Unit Testing/ Compression to your MSBuild</a></li>
<li><a href='http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/' rel='bookmark' title='Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;'>Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>A useful snippet of code I used in a web services project a while ago which i just stumbled back across recently- allows you to make a deep copy of an array, where you would normally get a shallow copy, stopping you from manipulating it independently from the source.  This gives you a completely fresh and separate copy.  The original is serialised to a memory, then a new instance created from the serialised representation (so obviously if it&#8217;s an array of custom objects, those objects will need to be marked serializable)</p>
<pre class="brush: csharp">
OrderItem[] order_items_clone;
using( MemoryStream ms = new MemoryStream())
{
	System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
	formatter.Serialize(ms,order_items);
	ms.Seek(0 , SeekOrigin.Begin);
	order_items_clone = (OrderItem[])formatter.Deserialize(ms);
}
</pre>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/a-complete-list-of-net-serializers-in-3-5/' rel='bookmark' title='A complete list of .NET Serializers in 3.5'>A complete list of .NET Serializers in 3.5</a></li>
<li><a href='http://codeblog.shawson.co.uk/adding-javascript-unit-testing-compression-to-your-build/' rel='bookmark' title='Adding Javascript Unit Testing/ Compression to your MSBuild'>Adding Javascript Unit Testing/ Compression to your MSBuild</a></li>
<li><a href='http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/' rel='bookmark' title='Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;'>Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/deep-copy-array-collection-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

