<?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>Barry Jones &#187; Useful MVC Resources &#8211; Barry Jones</title>
	<atom:link href="http://www.barryjones.me.uk/category/development/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.barryjones.me.uk</link>
	<description>General Ramblings</description>
	<lastBuildDate>Mon, 06 Sep 2010 10:05:24 +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>Useful MVC Resources</title>
		<link>http://www.barryjones.me.uk/2010/09/useful-mvc-resources/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=useful-mvc-resources</link>
		<comments>http://www.barryjones.me.uk/2010/09/useful-mvc-resources/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 08:00:03 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Pattern]]></category>
		<category><![CDATA[Resources]]></category>

		<guid isPermaLink="false">http://www.barryjones.me.uk/?p=234</guid>
		<description><![CDATA[While learning anything new there are times when you stumble upon information on the Internet that really seems to help. Here a list of links and websites that have helped me get a better understanding of the Microsoft&#8217;s MVC .NET Framework, it&#8217;s architecture and how to use it. But first the pattern: Martin Fowlers Discussion [...]]]></description>
			<content:encoded><![CDATA[<p>While learning anything new there are times when you stumble upon information on the Internet that really seems to help. Here a list of links and websites that have helped me get a better understanding of the <em>Microsoft&#8217;s <acronym title="Model View Controller">MVC</acronym> .NET Framework</em>, it&#8217;s architecture and how to use it.<span id="more-234"></span></p>
<p>But first the pattern: <a title="MVC Pattern Description" href="http://martinfowler.com/eaaDev/uiArchs.html" target="_blank">Martin Fowlers Discussion of the MVC Pattern</a>.</p>
<h3>General MVC Resources</h3>
<p>These links are websites with lots of various information about <em><acronym title="Model View Controller">MVC</acronym></em>, with no specific focus.</p>
<ul>
<li><a title="Microsoft MVC Website" href="http://www.asp.net/mvc" target="_blank">Microsoft&#8217;s MVC Framework Website</a></li>
<li><a title="Scott Hanselman on MVC" href="http://www.hanselman.com/blog/CategoryView.aspx?category=ASP.NET+MVC" target="_blank">All of Scott Hanselman&#8217;s MVC Posts</a></li>
<li><a title="Scott Gu" href="http://weblogs.asp.net/Scottgu" target="_blank">Scott Guthrie for eveything .NET</a></li>
<li><a title="MSDN MVC Introduction" href="http://msdn.microsoft.com/en-us/magazine/cc337884.aspx" target="_blank">An introduction to MVC</a></li>
<li><a title="MSDN MVC Resources" href="http://msdn.microsoft.com/en-us/library/dd394709%28VS.100%29.aspx" target="_blank">A list of MSDN resources for learning the details of the MVC Framework</a></li>
</ul>
<h3>Architecture and Pipeline</h3>
<p>A very good description of the full request response pipeline in MVC.NET, this is for version 1.0 but the information is still useful.</p>
<ul>
<li><a title="MVC Architecture" href="http://dotnetslackers.com/articles/aspnet/AnArchitecturalViewOfTheASPNETMVCFramework.aspx" target="_blank">Architectural Overview of MVC Framework</a></li>
<li><a title="MVC Pipeline Lifecycle" href="http://blog.codeville.net/2007/11/20/aspnet-mvc-pipeline-lifecycle/" target="_blank">V1.0 Request/Response Pipeline Overview</a></li>
</ul>
<h3>Model Binding Information</h3>
<ul>
<li><a title="MVC Model Binders" href="http://blog.maartenballiauw.be/post/2008/10/02/Using-the-ASPNET-MVC-ModelBinder-attribute-Second-part.aspx" target="_blank">Creating a Model Binder</a></li>
<li><a title="IModelBinder implementation" href="http://panteravb.com/blog/posts/2008/10/2/imodelbinder-with-autobinder.ashx" target="_blank">IModelBinder Autobinding</a></li>
</ul>
<h3>Routing</h3>
<ul>
<li><a title="MSDN description of MVC Routing" href="http://msdn.microsoft.com/en-us/library/cc668201%28VS.100%29.aspx" target="_blank">MSDN Review of the MVC Routing Process</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2010/09/useful-mvc-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>.NET Documentation in Live Documenter</title>
		<link>http://www.barryjones.me.uk/2010/07/net-documentation-in-live-documenter/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=net-documentation-in-live-documenter</link>
		<comments>http://www.barryjones.me.uk/2010/07/net-documentation-in-live-documenter/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 22:55:19 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://www.barryjones.me.uk/?p=353</guid>
		<description><![CDATA[Today The Box Software released their .NET documentation tool the Live Documenter. There are certainly other tools to output static compiled help files. But the Live Documenter is different. After we have painstakingly entered all of that XML code comments in our source code. We need a nice way to see the fruits of our [...]]]></description>
			<content:encoded><![CDATA[<p>Today <a title="The Box Software" href="http://theboxsoftware.com" target="_blank">The Box Software</a> released their .NET documentation tool the <a title=".NET documentation tool Live Documenter" href="http://theboxsoftware.com/products/live-documenter/" target="_blank">Live Documenter</a>. There are certainly other tools to output static compiled help files. But the Live Documenter is different.</p>
<p>After we have painstakingly entered all of that XML code comments in our source code. We need a nice way to see the fruits of our labours. NDoc emerged years ago and provided a way to get your documentation in to a compiled CHM file, but crashed and burned when generics was released in .NET 2. Documentation tools/generators whatever have never kind of cut the mustard since then.<span id="more-353"></span></p>
<p>Lets have a look at the Live Documenter.</p>
<h2>.NET documentation has never looked so good</h2>
<p>The Live Documenter supports all currently available versions of the .NET framework, project and solution files. So when you want to view your documentation you can just simply point it at your current solution file. You will be greeted by the library view.</p>
<div id="attachment_354" class="wp-caption alignnone" style="width: 310px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2010/07/ld-assemblies.png" rel="lightbox[353]"><img class="size-medium wp-image-354 " title="Assemblies" src="http://www.barryjones.me.uk/wp-content/uploads/2010/07/ld-assemblies-300x197.png" alt="View of libraries in the Live Documenter" width="300" height="197" /></a><p class="wp-caption-text">Assemblies in Live Documenter</p></div>
<p>You are presented with a list of all of the libraries in the solution. The black ones have XML comments the grey ones have not. When you select one of the libraries the list of namespaces is displayed in the reading panel on the right. Nice and simple.</p>
<p>Lets just jump in and see what a documented class looks like.</p>
<div id="attachment_358" class="wp-caption alignnone" style="width: 310px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2010/07/ld-class.png" rel="lightbox[353]"><img class="size-medium wp-image-358" title="Classes in Live Documenter" src="http://www.barryjones.me.uk/wp-content/uploads/2010/07/ld-class-300x197.png" alt="A view of a class in the Live Documenter" width="300" height="197" /></a><p class="wp-caption-text">Classes in Live Documenter</p></div>
<p>The class is displayed as you expect. The remarks you entered are displayed, the see links you created are displayed AND they link through to the associated class, method, property. The inheritance tree is displayed and the see also links from the documentation. The tree view shows all the other classes, enumeration, interfaces in the same namespace.</p>
<pre class="code">/// &lt;summary&gt;
/// The AssemblyDef provides the top level information and entry point to
/// all types, methods etc reflected from a .NET executable.
/// &lt;/summary&gt;
/// &lt;remarks&gt;
/// &lt;para&gt;The AssemblyDef is the starting point for obtaining reflected information
/// about a .NET assembly. This information is obtained by parsing and discerning
/// information about &lt;see cref="TypeDef"/&gt;s, &lt;see cref="MethodDef"/&gt;s etc from
/// the .NET metadata stored in the &lt;see cref="PeCoffFile"/&gt;.&lt;/para&gt;
/// &lt;para&gt;The assembly implements a mechanism for generating unique identifiers
/// that can be assigned to each of the elements reflected in this assembly. The
/// unique identifier is not really required but can help other applications to
/// store keys and find reflected elements more quickly and uses less memory than
/// string based unique identifiers.&lt;/para&gt;
/// &lt;example&gt;
/// &lt;code&gt;
/// // Instantiate from a full file path and name
/// AssemblyDef assembly = AssemblyDef.Create(myAssemblyPath);
///
/// // Instantiate from an already existing loaded metadata file
/// PeCoffFile peCoffFile = new PeCoffFile(myAssemblyPath);
/// AssemblyDef assembly = AssemblyDef.Create(peCoffFile);
/// &lt;/code&gt;
/// &lt;/example&gt;
/// &lt;/remarks&gt;
/// &lt;seealso cref="PeCoffFile"/&gt;
</pre>
<p>There is a full list of supported XML tags on the <a title="Available XML comment tags on MSDN" href="http://msdn.microsoft.com/en-us/library/5ast78ax.aspx" target="_blank">MSDN website</a>.</p>
<p>The method view is just as good. It displays the exceptions, type parameters, parameters, summaries and remarks as expected.</p>
<div id="attachment_364" class="wp-caption alignnone" style="width: 310px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2010/07/ld-method.png" rel="lightbox[353]"><img class="size-medium wp-image-364" title="A generic method in Live Documenter" src="http://www.barryjones.me.uk/wp-content/uploads/2010/07/ld-method-300x197.png" alt="The live documenter shows a generic method" width="300" height="197" /></a><p class="wp-caption-text">Methods in the Live Documenter</p></div>
<p>You can also search the whole solution for methods, classes etc. The Live Documenter will show you an auto-complete search box with the results for you query.</p>
<div id="attachment_366" class="wp-caption alignnone" style="width: 310px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2010/07/ld-searching.png" rel="lightbox[353]"><img class="size-medium wp-image-366" title="Searching in the Live Documenter" src="http://www.barryjones.me.uk/wp-content/uploads/2010/07/ld-searching-300x197.png" alt="Autocomplete searching in the live documenter" width="300" height="197" /></a><p class="wp-caption-text">Searching in the Live Documenter</p></div>
<p>It handily displays the summary text with each result to help you figure out which result you was actually looking for.</p>
<p>There is plenty more to get excited about with the Live Documenter, it&#8217;s super fast, really good looking and I suggest you download your FREE copy from <a title="Download The Live Documenter by the Box Software" href="http://theboxsoftware.com/products/live-documenter/" target="_blank">http://theboxsoftware.com/products/live-documenter/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2010/07/net-documentation-in-live-documenter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Route Debugging in MVC.NET</title>
		<link>http://www.barryjones.me.uk/2009/10/quick-route-debugging-in-mvc-net/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quick-route-debugging-in-mvc-net</link>
		<comments>http://www.barryjones.me.uk/2009/10/quick-route-debugging-in-mvc-net/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 10:26:43 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://www.barryjones.me.uk/?p=141</guid>
		<description><![CDATA[Here is a quick way of getting detailed information about which route has been accepted and why in MVC.NET. The code below should be placed in your Application_EndRequest event handler in global.asax. By placing a break point in the code directly after evaluation you can see a collection of all the routes, if it matched [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick way of getting detailed information about which route has been accepted and why in MVC.NET.</p>
<p>The code below should be placed in your Application_EndRequest event handler in global.asax. By placing a break point in the code directly after evaluation you can see a collection of all the routes, if it matched the request and a reference to the RouteData to see more detailed information.</p>
<p>This code works by re-evaluating each of the Routes defined in your application against the current request. The first match in the collection is the match that MVC will have used to handle your request.<span id="more-141"></span></p>
<pre class="code">List&lt;object&gt; routes = new List&lt;object&gt;();
foreach (System.Web.Routing.Route current in System.Web.Routing.RouteTable.Routes) {
	System.Web.Routing.RouteData data = current.GetRouteData(
		new HttpContextWrapper(HttpContext.Current)
		);
	bool matches = data != null;
	routes.Add(new { Match=matches, Url=current.Url.ToString(), Data=data});
}</pre>
<p>For a better long term implementation try using <a title="Phil Haack's ASP.NET Routing Debugger" href="http://haacked.com/archive/2008/03/13/url-routing-debugger.aspx" target="_blank">Phil Haack&#8217;s</a> debugging implementation or get the route debugging code from the <a title="ASP.NET MVC Unleased" href="http://www.informit.com/store/product.aspx?isbn=9780672329982" target="_blank">ASP.NET MVC Unleashed</a> book.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2009/10/quick-route-debugging-in-mvc-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Current Work: Live Documenter</title>
		<link>http://www.barryjones.me.uk/2009/10/current-work-live-documenter/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=current-work-live-documenter</link>
		<comments>http://www.barryjones.me.uk/2009/10/current-work-live-documenter/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 21:43:47 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[My Projects]]></category>
		<category><![CDATA[CLR]]></category>
		<category><![CDATA[personal]]></category>
		<category><![CDATA[XML Comments]]></category>

		<guid isPermaLink="false">http://www.barryjones.me.uk/?p=48</guid>
		<description><![CDATA[I had nothing else to talk about so I thought I would give a little ramble on my current project. It has been &#8216;code named&#8217; Live Documenter, which will probably end up being its final name as well &#8211; if only I was more creative. OK, onward! Basically since NDoc curled up and died a [...]]]></description>
			<content:encoded><![CDATA[<p>I had nothing else to talk about so I thought I would give a little ramble on my current project. It has been &#8216;code named&#8217; Live Documenter, which will probably end up being its final name as well &#8211; if only I was more creative. OK, onward!</p>
<p>Basically since <a title="NDoc stagnating since 2005" href="http://ndoc.sourceforge.net/" target="_blank">NDoc</a> curled up and died a long time ago I have really wanted a nice xml comment documenter to read all those lovely comments I have been painstakingly hand crafting since , well, as long as I can remember. This has been curled up at the back of mind for ages. And a little while ago I decided I would start faffing around with the .NET meta-data and just try to learn a little more about how the <acronym title="Common Language Runtime">CLR</acronym> holds it&#8217;s data in <acronym title="Portable Executable">PE</acronym> files, what kind of data and well.. OK I can&#8217;t justify it really. Anyway; two thoughts collided and the rest is unwritten history.<span id="more-48"></span></p>
<h2>What it Does</h2>
<p>This documentor takes a solution, project or library and churns through all the internal gubbins of the built libraries for the <acronym title="Visual Studio">VS</acronym> files or itself for the DLL. It then locates the lovely XML comment files, mingles them together and spits out some nice legible information. I haven&#8217;t painted that in the most beautiful light but I am British so it remains understated.</p>
<ul>
<li>Reads VS Solution, Project and Library files</li>
<li>Parses XML comments (supports the basic <a href="http://msdn.microsoft.com/en-us/library/5ast78ax(VS.80).aspx" target="_blank">Microsoft set</a>) to produce documentation</li>
<li>Updates live the changes you make to the your source code</li>
<li>Allows searching of types, properties and methods</li>
<li>Supports code comments for generic types and methods</li>
<li>Provides syntax in C# or Visual Basic</li>
</ul>
<p>It was a real struggle getting information about the internal workings of PE files, the Internet is a little sparse in this regard, so I had to get the aid of two books <a title=".NET IL Assembler" href="http://www.amazon.co.uk/Inside-NET-IL-Assembler-Lidin/dp/0735615470/ref=sr_1_2?ie=UTF8&amp;s=books&amp;qid=1255037193&amp;sr=8-2" target="_blank">.NET IL Assembler</a> and <a title="Reversing - The secrets of reverse engineering" href="http://www.amazon.co.uk/Reversing-Secrets-Engineering-Eldad-Eilam/dp/0764574817/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1255037247&amp;sr=1-1" target="_blank">Reversing</a> to help me on the way. Whilst I was reinventing the wheel Microsoft released an open source reflection library (which I can no longer find a link to) which seems to do everything, ah well. However, I think I will in future posts, describe in a little more detail what I did and learnt while making this app.</p>
<h2>Appearances can be Deceiving</h2>
<p>This doesn&#8217;t look the best at the moment, but it&#8217;s still in development so bear with me! I really need to polish the front end up and apply some UX magic; so with that in mind lets have a look at some screenies.</p>
<div id="attachment_105" class="wp-caption alignleft" style="width: 160px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/type-view.png" rel="lightbox[48]"><img class="size-thumbnail wp-image-105" title="Live Documentor - Type Page" src="http://www.barryjones.me.uk/wp-content/uploads/2009/10/type-view-150x102.png" alt="Live Documentor - Type Page" width="150" height="102" /></a><p class="wp-caption-text">View of a Class</p></div>
<div id="attachment_111" class="wp-caption alignright" style="width: 160px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/namespace-view.png" rel="lightbox[48]"><img class="size-thumbnail wp-image-111" title="namespace view" src="http://www.barryjones.me.uk/wp-content/uploads/2009/10/namespace-view-150x102.png" alt="namespace view" width="150" height="102" /></a><p class="wp-caption-text">View of a Namespace</p></div>
<p>The class view has all of the information you would expect. Full namespace declaration, deceleration syntax, all your lovely comments, inheritance tree and by the powers of WPF lots of control over how you view the page. All of the param references, type references, exception information (for methods) is linked up from the comments. The UI currently allows you to view easily which libraries have comments and which don&#8217;t.</p>
<p>As you can see by the method view below, it supports generic types and methods. Type, method, property etc signatures are generated and can be changed to multiple languages; although I have only written code to support VB and C# at the moment.</p>
<div id="attachment_113" class="wp-caption alignleft" style="width: 160px"><a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/method-view-generic.gif" rel="lightbox[48]"><img class="size-thumbnail wp-image-113" title="Live Documentor - View of Generic Method" src="http://www.barryjones.me.uk/wp-content/uploads/2009/10/method-view-generic-150x107.gif" alt="View of a Method" width="150" height="107" /></a><p class="wp-caption-text">View of a Method</p></div>
<p>I all in all am pretty excited about where this is going at the moment and for the ideas I have about where it will be going on a more long term basis. One little thing I &#8211; in the long term &#8211; am hoping to get in there is dynamically creating <a title="Unified Modelling Language" href="http://en.wikipedia.org/wiki/Unified_Modeling_Language" target="_blank">UML</a> diagrams. The idea of being able to see a methods full sequence diagram, cant be anything but a help for people working on new projects or revisiting old ones!</p>
<p>Finally, the main idea behind this application is that it is used more like a live reference, an open book; which you would have open at the same time as a project. Because of this the application will continually update itself based on changes you make to your solutions, projects, code and comments. I thought that was a little different from your normal wait for application to generate static pages, currently event with a large 20 project solution this still opens quickly and is extremely usable. I hope that has made you interested and I will speak up again when I have something that I can throw out there.</p>
<p>This application will be made available from my company, <a href="http://www.theboxsoftware.com">The Box Software</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2009/10/current-work-live-documenter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically Populate DTOs</title>
		<link>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatically-populate-dtos</link>
		<comments>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/#comments</comments>
		<pubDate>Tue, 06 Oct 2009 20:07:09 +0000</pubDate>
		<dc:creator>Barry Jones</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[DTO]]></category>
		<category><![CDATA[Pattern]]></category>

		<guid isPermaLink="false">http://carl.barryjones.me.uk/?p=15</guid>
		<description><![CDATA[The lowly DTO, a pattern described by Martin Fowler that enables you to reduce the number of API calls you make across a remote boundary; it allows this by grouping all the data in to a new data type and returning that instead. I have however found that this pattern can cause you to write [...]]]></description>
			<content:encoded><![CDATA[<p>The lowly <a title="DTO Pattern" href="http://martinfowler.com/eaaCatalog/dataTransferObject.html"><acronym title="Data Transfer Object">DTO</acronym></a>, a pattern described by <a title="Martin Fowler" href="http://martinfowler.com/" target="_blank">Martin Fowler</a> that enables you to reduce the number of API calls you make across a remote boundary; it allows this by grouping all the data in to a new data type and returning that instead. I have however found that this pattern can cause you to write a lot of code that is nothing more than property setting. The code provided in this post (<a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">here</a>) allows you to automate the population of these <acronym title="Data Transfer Object">DTO</acronym>s saving you time, so you can get on with something more important like drinking coffee.<span id="more-15"></span></p>
<h2>Automating DTO Population</h2>
<p>First of all grab yourself a copy of the <a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">source</a> code. A general overview of the process is; you specify — using attributes — the mappings between your business objects and your data transfer objects. These attributes can describe simple properties, complex properties and collections. After that is done, throw the object at the converter and Bob&#8217;s your uncle!</p>
<h3>Mapping DTO Properties with Attributes</h3>
<p>There are two attributes DTOSimpleMapper and DTOCollectionMapper; the basic signature of the attributes is shown below.</p>
<pre class="code">[DTOSimpleMapper(params string[] fields)]
[DTOCollectionMapper(Type ofType, string fromField)]</pre>
<pre class="code">[DTOSimpleMapper("FromProperty.Child.Identifier")]
public int ConvertedProperty;</pre>
<p>The ‘fields’ and ‘fromField’ parameters describe the property on the origin object that is to be converted. The destination for the conversion is always the property the attribute is decorating. The fields are represented as a string where the field is a child property the ‘.’ notation can be used to indicate this. I.e. &#8220;Parent.Child.Child&#8221;.<br />
The params string[] parameters on both attributes can be used to describe more complex conversions, when the converting types have multiple properties the conversion can be described by passing in an array of strings which define the from and to properties. I.e:</p>
<pre class="code">[DTOSimpleMapper("Prop1.Prop2=Identifier", "Prop2.Prop1=Name")]</pre>
<p>The first parameter on the DTOCollectionMapper tells the converter what the destination array elements are:</p>
<pre class="code">[DTOCollectionMapper(typeof(string), "FromProperty"]
public string[] ConvertedCollection;</pre>
<p>The converter will work with any collection that implements IEnumerable. As with the simple mapper, the property name can describe more complex conversions. This is useful where you have a generic <acronym title="Data Transfer Object">DTO</acronym> that is used to describe many elements:</p>
<pre class="code">[DTOCollectionMapper(typeof(IdentifiedElement), "FromPoperty", "Identifier=Identifier",
"Child.Name=Name")]
public List Children;</pre>
<p>Finally where the conversions are more complex the type for the property can describe its own conversion:</p>
<pre class="code">Public class RelatedChildDTO {
     [DTOSimpleMapper("Identifier")] public int Identifier;
     [DTOSimpleMapper("Name")] public string Name;
}
Public class ParentDTO {
     [DTOSimpleMapper("Child")]
     public RelatedChildDTO Child;
}</pre>
<p>With the above example the converter will check the type of instance it is creating and use the attributes described on that type to perform the conversion.</p>
<h2>Conditional Population</h2>
<p>Both of the attributes allow for Type conditional conversions as well, both are overloaded with a type property that is checked in the conversion process and only performed when the origin type is the same:</p>
<pre class="code">[DTOSimpleMapper(typeof(ConditionalBusinessObject), "FromProperty")]
public string ConvertedProperty;</pre>
<h2>Automatic Conversion</h2>
<p>Now you have described the way objects are converted we are left with actual conversion, the library has a Converter class with a simple static method called Convert. This method takes an instance of an origin object and a type for the destination object.</p>
<pre class="code">BusinessObject bus = new BusinessObject();
// set business properties
DTO dto = (DTO)Convertor.Convert(bus, typeof(DTO));</pre>
<p>The result of this method call is that the <acronym title="Data Transfer Object">DTO</acronym> is created and populated using the attributes, the conversion is done!<br />
Here is the <a href="http://www.barryjones.me.uk/wp-content/uploads/2009/10/BarryJones.DataTransferObjects.zip">source code</a>, it contains test classes which should give you a better idea of how it all works, enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.barryjones.me.uk/2009/10/automatically-populate-dtos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

