<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Cloning Object Properties via Reflection</title>
	<atom:link href="http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/feed/" rel="self" type="application/rss+xml" />
	<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/</link>
	<description>Graham O&#039;Neale – Deep In .NET Development: ASP.NET, MVC, jQuery, WPF, WCF, Silverlight</description>
	<lastBuildDate>Wed, 28 Sep 2011 23:00:45 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Steve Jensen</title>
		<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/comment-page-1/#comment-33143</link>
		<dc:creator>Steve Jensen</dc:creator>
		<pubDate>Sun, 03 Jul 2011 05:30:41 +0000</pubDate>
		<guid isPermaLink="false">http://goneale.wordpress.com/?p=311#comment-33143</guid>
		<description>here is the code that works in VS 2010 VB.NET:
 Public Module ReflectionExtensions
		&#039;&#039;&#039; 
		&#039;&#039;&#039; Clone properties from an original object to a destination object.
		&#039;&#039;&#039; See for more info: http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/
		&#039;&#039;&#039; NOTE: Does not currently handle list&#039;s.
		&#039;&#039;&#039; 
		&#039;&#039;&#039; 
		&#039;&#039;&#039; 
		&#039;&#039;&#039; 
		&#039;&#039;&#039; 
         _
        Public Sub CloneProperties(Of T1, T2)(ByVal origin As T1, ByVal destination As T2)
            &#039; Instantiate if necessary
            If destination Is Nothing Then
                Throw New ArgumentNullException(&quot;destination&quot;, &quot;Destination object must first be instantiated.&quot;)
            End If
            &#039; Loop through each property in the destination
            For Each destinationProperty As Reflection.PropertyInfo In destination.[GetType]().GetProperties()
                &#039; find and set val if we can find a matching property name and matching type in the origin with the origin&#039;s value               
                If origin IsNot Nothing AndAlso destinationProperty.CanWrite Then
                    For Each originProperty As Reflection.PropertyInfo In origin.[GetType]().GetProperties()
                        If destinationProperty.CanWrite AndAlso originProperty.CanRead AndAlso (originProperty.Name = destinationProperty.Name AndAlso originProperty.PropertyType Is destinationProperty.PropertyType) Then
                            destinationProperty.SetValue(destination, originProperty.GetValue(origin, Nothing), Nothing)
                        End If
                    Next
                End If
            Next

        End Sub
	End Module</description>
		<content:encoded><![CDATA[<p>here is the code that works in VS 2010 VB.NET:<br />
 Public Module ReflectionExtensions<br />
		&#8221;&#8217;<br />
		&#8221;&#8217; Clone properties from an original object to a destination object.<br />
		&#8221;&#8217; See for more info: <a href="http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/" rel="nofollow">http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/</a><br />
		&#8221;&#8217; NOTE: Does not currently handle list&#8217;s.<br />
		&#8221;&#8217;<br />
		&#8221;&#8217;<br />
		&#8221;&#8217;<br />
		&#8221;&#8217;<br />
		&#8221;&#8217;<br />
         _<br />
        Public Sub CloneProperties(Of T1, T2)(ByVal origin As T1, ByVal destination As T2)<br />
            &#8216; Instantiate if necessary<br />
            If destination Is Nothing Then<br />
                Throw New ArgumentNullException(&#8220;destination&#8221;, &#8220;Destination object must first be instantiated.&#8221;)<br />
            End If<br />
            &#8216; Loop through each property in the destination<br />
            For Each destinationProperty As Reflection.PropertyInfo In destination.[GetType]().GetProperties()<br />
                &#8216; find and set val if we can find a matching property name and matching type in the origin with the origin&#8217;s value<br />
                If origin IsNot Nothing AndAlso destinationProperty.CanWrite Then<br />
                    For Each originProperty As Reflection.PropertyInfo In origin.[GetType]().GetProperties()<br />
                        If destinationProperty.CanWrite AndAlso originProperty.CanRead AndAlso (originProperty.Name = destinationProperty.Name AndAlso originProperty.PropertyType Is destinationProperty.PropertyType) Then<br />
                            destinationProperty.SetValue(destination, originProperty.GetValue(origin, Nothing), Nothing)<br />
                        End If<br />
                    Next<br />
                End If<br />
            Next</p>
<p>        End Sub<br />
	End Module</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ivan</title>
		<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/comment-page-1/#comment-8220</link>
		<dc:creator>Ivan</dc:creator>
		<pubDate>Thu, 08 Apr 2010 07:20:04 +0000</pubDate>
		<guid isPermaLink="false">http://goneale.wordpress.com/?p=311#comment-8220</guid>
		<description>Cool!
Thanks.</description>
		<content:encoded><![CDATA[<p>Cool!<br />
Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Andy</title>
		<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/comment-page-1/#comment-2409</link>
		<dc:creator>Andy</dc:creator>
		<pubDate>Thu, 10 Sep 2009 03:50:46 +0000</pubDate>
		<guid isPermaLink="false">http://goneale.wordpress.com/?p=311#comment-2409</guid>
		<description>For a collection type property, it just clone the reference, not a deep clone, so if you add a new item to the cloned collection, the sourcee collection also add a new one, this is what I don&#039;t need, maybe some people also doesn&#039;t need.

Before read your article, I also write such a methond, the main problem is I can&#039;t deep clone a collection type property.</description>
		<content:encoded><![CDATA[<p>For a collection type property, it just clone the reference, not a deep clone, so if you add a new item to the cloned collection, the sourcee collection also add a new one, this is what I don&#8217;t need, maybe some people also doesn&#8217;t need.</p>
<p>Before read your article, I also write such a methond, the main problem is I can&#8217;t deep clone a collection type property.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Graham O'Neale</title>
		<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/comment-page-1/#comment-104</link>
		<dc:creator>Graham O'Neale</dc:creator>
		<pubDate>Mon, 16 Feb 2009 23:18:58 +0000</pubDate>
		<guid isPermaLink="false">http://goneale.wordpress.com/?p=311#comment-104</guid>
		<description>No problem!</description>
		<content:encoded><![CDATA[<p>No problem!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Coxhead</title>
		<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/comment-page-1/#comment-103</link>
		<dc:creator>John Coxhead</dc:creator>
		<pubDate>Mon, 16 Feb 2009 15:45:24 +0000</pubDate>
		<guid isPermaLink="false">http://goneale.wordpress.com/?p=311#comment-103</guid>
		<description>Exctly what I was looking for ! Thanks !</description>
		<content:encoded><![CDATA[<p>Exctly what I was looking for ! Thanks !</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: DotNetShoutout</title>
		<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/comment-page-1/#comment-102</link>
		<dc:creator>DotNetShoutout</dc:creator>
		<pubDate>Mon, 16 Feb 2009 11:35:44 +0000</pubDate>
		<guid isPermaLink="false">http://goneale.wordpress.com/?p=311#comment-102</guid>
		<description>&lt;strong&gt;Cloning Object Properties via Reflection « {Programming} &amp; Life...&lt;/strong&gt;

Thank you for submitting this cool story - Trackback from DotNetShoutout...</description>
		<content:encoded><![CDATA[<p><strong>Cloning Object Properties via Reflection « {Programming} &amp; Life&#8230;</strong></p>
<p>Thank you for submitting this cool story &#8211; Trackback from DotNetShoutout&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cloning Object Properties via Reflection « {Programming} &#38; Life &#124; apartmentcost.com</title>
		<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/comment-page-1/#comment-101</link>
		<dc:creator>Cloning Object Properties via Reflection « {Programming} &#38; Life &#124; apartmentcost.com</dc:creator>
		<pubDate>Mon, 16 Feb 2009 06:07:28 +0000</pubDate>
		<guid isPermaLink="false">http://goneale.wordpress.com/?p=311#comment-101</guid>
		<description>[...] Cloning Object Properties via Reflection « {Programming} &amp; Life [...]</description>
		<content:encoded><![CDATA[<p>[...] Cloning Object Properties via Reflection « {Programming} &amp; Life [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Cloning Object Properties via Reflection « {Programming} &#38; Life &#124; extensiveproperty.com</title>
		<link>http://goneale.com/2009/02/16/cloning-object-properties-via-reflection/comment-page-1/#comment-100</link>
		<dc:creator>Cloning Object Properties via Reflection « {Programming} &#38; Life &#124; extensiveproperty.com</dc:creator>
		<pubDate>Mon, 16 Feb 2009 05:36:38 +0000</pubDate>
		<guid isPermaLink="false">http://goneale.wordpress.com/?p=311#comment-100</guid>
		<description>[...] Cloning Object Properties via Reflection « {Programming} &amp; Life [...]</description>
		<content:encoded><![CDATA[<p>[...] Cloning Object Properties via Reflection « {Programming} &amp; Life [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

