<?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 for Scott Williams's Ramblings</title>
	<atom:link href="http://blogs.us.sogeti.com/swilliams/comments/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.us.sogeti.com/swilliams</link>
	<description>I write code. Hopefully, it's good.</description>
	<pubDate>Thu, 20 Jun 2013 09:52:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Comment on Amusing Bad Programming Tip by Daniel Maher</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/04/27/amusing-bad-programming-tip/comment-page-1/#comment-78</link>
		<dc:creator>Daniel Maher</dc:creator>
		<pubDate>Thu, 06 May 2010 15:32:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50105000#comment-78</guid>
		<description>Proper formatting would make it a little easier to recognize:

Product p = new Product { 
      ProductName = Console.ReadLine() 
};

I like this feature, but I prefer to initialize each member on a separate line so it's easier to see what's happening.</description>
		<content:encoded><![CDATA[<p>Proper formatting would make it a little easier to recognize:</p>
<p>Product p = new Product {<br />
      ProductName = Console.ReadLine()<br />
};</p>
<p>I like this feature, but I prefer to initialize each member on a separate line so it&#8217;s easier to see what&#8217;s happening.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Amusing Bad Programming Tip by Scott Williams</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/04/27/amusing-bad-programming-tip/comment-page-1/#comment-73</link>
		<dc:creator>Scott Williams</dc:creator>
		<pubDate>Wed, 28 Apr 2010 16:07:52 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50105000#comment-73</guid>
		<description>Randy, you are correct. That's why it's a BAD programming tip, and why I said not to do it.</description>
		<content:encoded><![CDATA[<p>Randy, you are correct. That&#8217;s why it&#8217;s a BAD programming tip, and why I said not to do it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Amusing Bad Programming Tip by Randy Stegbauer</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/04/27/amusing-bad-programming-tip/comment-page-1/#comment-72</link>
		<dc:creator>Randy Stegbauer</dc:creator>
		<pubDate>Wed, 28 Apr 2010 12:26:35 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50105000#comment-72</guid>
		<description>I don't understand the syntax.  I'm guessing that there is a class variable called 'ProductName' that is initialized by the Console.ReadLine().  Right?

I wouldn't do that initialization simply because a console application should also be able to get the parameters from the command line as well.</description>
		<content:encoded><![CDATA[<p>I don&#8217;t understand the syntax.  I&#8217;m guessing that there is a class variable called &#8216;ProductName&#8217; that is initialized by the Console.ReadLine().  Right?</p>
<p>I wouldn&#8217;t do that initialization simply because a console application should also be able to get the parameters from the command line as well.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Amusing Bad Programming Tip by Scott Williams</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/04/27/amusing-bad-programming-tip/comment-page-1/#comment-69</link>
		<dc:creator>Scott Williams</dc:creator>
		<pubDate>Tue, 27 Apr 2010 22:13:16 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50105000#comment-69</guid>
		<description>Hahaha. I found by quickly testing some WCF code, thinking "this couldn't possibly work... oh crap, it does!" 

I think mixing class initialization in Data Binding doesn't feel "dirty" because it is completely abstracted away from the user. There's no way to abstract a Console.ReadLine in such a way.</description>
		<content:encoded><![CDATA[<p>Hahaha. I found by quickly testing some WCF code, thinking &#8220;this couldn&#8217;t possibly work&#8230; oh crap, it does!&#8221; </p>
<p>I think mixing class initialization in Data Binding doesn&#8217;t feel &#8220;dirty&#8221; because it is completely abstracted away from the user. There&#8217;s no way to abstract a Console.ReadLine in such a way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Amusing Bad Programming Tip by Eric Swanson</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/04/27/amusing-bad-programming-tip/comment-page-1/#comment-68</link>
		<dc:creator>Eric Swanson</dc:creator>
		<pubDate>Tue, 27 Apr 2010 22:09:09 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50105000#comment-68</guid>
		<description>Yikes! Although I'm certain smart developers could convince me that this is no different than inline anonymous delegates, which I'm a big fan of. Interesting that I'm opposed to the example, but I'm all for the delegates. Hmm... why does that feel so dirty?

Ah! Mixing user interaction with class initialization, but isn't that what Data Binding is essentially doing for us in other technologies like WPF? This is simply Data Binding for Console programs I suppose... Hmm... Okay, I reverse my thinking. I like it if it's being used as a form of Data Binding for Console programs on the primary console interaction code path and it's strictly apparent for this reason. But, if I were to find that floating deep in the guts of a program, you can bet there will be a conversation!</description>
		<content:encoded><![CDATA[<p>Yikes! Although I&#8217;m certain smart developers could convince me that this is no different than inline anonymous delegates, which I&#8217;m a big fan of. Interesting that I&#8217;m opposed to the example, but I&#8217;m all for the delegates. Hmm&#8230; why does that feel so dirty?</p>
<p>Ah! Mixing user interaction with class initialization, but isn&#8217;t that what Data Binding is essentially doing for us in other technologies like WPF? This is simply Data Binding for Console programs I suppose&#8230; Hmm&#8230; Okay, I reverse my thinking. I like it if it&#8217;s being used as a form of Data Binding for Console programs on the primary console interaction code path and it&#8217;s strictly apparent for this reason. But, if I were to find that floating deep in the guts of a program, you can bet there will be a conversation!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Use LINQ&#8217;s Select and Initializers to Make Mapping Easier by Eric Swanson</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/02/16/use-linqs-select-and-initializers-to-make-mapping-easier/comment-page-1/#comment-67</link>
		<dc:creator>Eric Swanson</dc:creator>
		<pubDate>Mon, 01 Mar 2010 18:39:24 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50104990#comment-67</guid>
		<description>Forgot to mention a major benefit: The transormation classes allow you to do deep-transformations (similar to deep cloning) for child object transforms.</description>
		<content:encoded><![CDATA[<p>Forgot to mention a major benefit: The transormation classes allow you to do deep-transformations (similar to deep cloning) for child object transforms.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Use LINQ&#8217;s Select and Initializers to Make Mapping Easier by Eric Swanson</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/02/16/use-linqs-select-and-initializers-to-make-mapping-easier/comment-page-1/#comment-66</link>
		<dc:creator>Eric Swanson</dc:creator>
		<pubDate>Mon, 01 Mar 2010 18:37:47 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50104990#comment-66</guid>
		<description>Couldn't agree more. I like to wrap the mapping in a class; something like "IBusinessEntityTransformer" that has two methods "TEntity ToEntity(TContract contract)" and "TContract ToContract(TEntity entity)".

With this, your implementation would look something like...

public class ClientServerTypeTransformer : IBusinessEntityTransformer
{
   public ClientType ToContract(ServerType entity)
   {
      return new ClientType()
      {
         Id = entity.ProductId
      };
   }

   public ServerType ToEntity(ClientType contract)
   {
      return new ServerType()
      {
         ProductId = entity.Id
      };
   }
}

Then, the LINQ statement becomes:

var converter = new ClientServerTypeTransformer();
var serverTypes = clientTypes.Select(contract =&#62; converter.ToEntity(contract));
// .ToList() is optional

*Seems like overkill for a 1-property class mapping, but I don't think I've ever had a 1-property class for these types of transforms.

**It's interesting to note that the VS2008 Samples from Microsoft had an implementation of this mapper class as "static" and called it "Translator". I can agree with "static", but I disagree with their naming convention, since "Transform" is an industry naming convention for this type of mapping (see: Extract-Transform-Load "ETL" or eXtensible Stylesheet Language Transformations "XSLT")</description>
		<content:encoded><![CDATA[<p>Couldn&#8217;t agree more. I like to wrap the mapping in a class; something like &#8220;IBusinessEntityTransformer&#8221; that has two methods &#8220;TEntity ToEntity(TContract contract)&#8221; and &#8220;TContract ToContract(TEntity entity)&#8221;.</p>
<p>With this, your implementation would look something like&#8230;</p>
<p>public class ClientServerTypeTransformer : IBusinessEntityTransformer<br />
{<br />
   public ClientType ToContract(ServerType entity)<br />
   {<br />
      return new ClientType()<br />
      {<br />
         Id = entity.ProductId<br />
      };<br />
   }</p>
<p>   public ServerType ToEntity(ClientType contract)<br />
   {<br />
      return new ServerType()<br />
      {<br />
         ProductId = entity.Id<br />
      };<br />
   }<br />
}</p>
<p>Then, the LINQ statement becomes:</p>
<p>var converter = new ClientServerTypeTransformer();<br />
var serverTypes = clientTypes.Select(contract =&gt; converter.ToEntity(contract));<br />
// .ToList() is optional</p>
<p>*Seems like overkill for a 1-property class mapping, but I don&#8217;t think I&#8217;ve ever had a 1-property class for these types of transforms.</p>
<p>**It&#8217;s interesting to note that the VS2008 Samples from Microsoft had an implementation of this mapper class as &#8220;static&#8221; and called it &#8220;Translator&#8221;. I can agree with &#8220;static&#8221;, but I disagree with their naming convention, since &#8220;Transform&#8221; is an industry naming convention for this type of mapping (see: Extract-Transform-Load &#8220;ETL&#8221; or eXtensible Stylesheet Language Transformations &#8220;XSLT&#8221;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Use LINQ&#8217;s Select and Initializers to Make Mapping Easier by Scott Williams</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/02/16/use-linqs-select-and-initializers-to-make-mapping-easier/comment-page-1/#comment-62</link>
		<dc:creator>Scott Williams</dc:creator>
		<pubDate>Thu, 18 Feb 2010 14:37:25 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50104990#comment-62</guid>
		<description>Thanks Mike, but I'm pretty sure Initializers weren't added until C# 3 :-). "return new ServerType{ ProductId = c.Id }"</description>
		<content:encoded><![CDATA[<p>Thanks Mike, but I&#8217;m pretty sure Initializers weren&#8217;t added until C# 3 :-). &#8220;return new ServerType{ ProductId = c.Id }&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Use LINQ&#8217;s Select and Initializers to Make Mapping Easier by Michael Melendez</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/02/16/use-linqs-select-and-initializers-to-make-mapping-easier/comment-page-1/#comment-61</link>
		<dc:creator>Michael Melendez</dc:creator>
		<pubDate>Thu, 18 Feb 2010 08:11:14 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50104990#comment-61</guid>
		<description>For data conversions you can also use the predicate functions that were added in 2.0.  But I still prefer your Linq method ;)

var serverTypes =
 clientTypes.ConvertAll(delegate(ClientType c) { return new ServerType{ ProductId = c.Id });</description>
		<content:encoded><![CDATA[<p>For data conversions you can also use the predicate functions that were added in 2.0.  But I still prefer your Linq method <img src='http://blogs.us.sogeti.com/swilliams/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>var serverTypes =<br />
 clientTypes.ConvertAll(delegate(ClientType c) { return new ServerType{ ProductId = c.Id });</p>
]]></content:encoded>
	</item>
	<item>
		<title>Comment on Use LINQ&#8217;s Select and Initializers to Make Mapping Easier by Devin Allen</title>
		<link>http://blogs.us.sogeti.com/swilliams/2010/02/16/use-linqs-select-and-initializers-to-make-mapping-easier/comment-page-1/#comment-60</link>
		<dc:creator>Devin Allen</dc:creator>
		<pubDate>Tue, 16 Feb 2010 16:27:55 +0000</pubDate>
		<guid isPermaLink="false">http://blogs.us.sogeti.com/swilliams/?p=50104990#comment-60</guid>
		<description>This is great stuff. I've been using a lot of LINQ features with MVC and it make so many things such a breeze.</description>
		<content:encoded><![CDATA[<p>This is great stuff. I&#8217;ve been using a lot of LINQ features with MVC and it make so many things such a breeze.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
