Creating Data Transfer Objects – Part 2

I have updated the console application DTO to version 2.0 to use attributes now to decorate the domain classes for code generation. This offers much better control of which domain classes should be used to create the Data Transfer Object classes. In addition, you can also decorate generate public properties that use domain classes as a return value.  

For example, if you decorate the following sample domain classes below with the DTO attribute like so 


using DTOAttributes;
namespace Example
{   
   [DTOAttributes.DTO]   
   public enum CustomerType   
   {       
      Regular,       
      Special   
   } 
   [DTOAttributes.DTO]
   public class Customer
   {

The DTO console app will generate the following code:

public enum CustomerTypeDTO      
{             
   Regular,             
   Special,      

public class CustomerDTO      
{             
   private List<EmailAddressDTO> _emails;
   [XmlElement(IsNullable = true)]
   public List<EmailAddressDTO> Emails
   {                    
      get { return _emails; }
      set { _emails = value; }
   } 

   private CustomerTypeDTO _type;
   [XmlElement(IsNullable = true)]
   public CustomerTypeDTO Type
   {                    
      get { return _type; }
      set { _type = value; }
   }

As you can see, it works pretty well. I’ve included the source code including the sample app. I’ve not update the CodeSmith template, yet as the console app is doing a fine job for me. For now. In my current project, this allows me to generate over 15,000 lines of code to create dozens of DTO classes automatically. Sweet! Enjoy!

You can download the new version here.

Creating Data Transfer Objects (DTO) with CodeSmith

I’ve created a template for CodeSmith to create Data Transfer Objects automatically by simply supplying the path and file to your domain model assembly file. This assembly should have all your business objects included. The template does the rest. I only spent two days on this but it works for the most part including generics. It basically uses reflection to create a DTO version of each business class.

 I was going to extend it by using Attributes to decorate class names as well as properties for your domain model; but, found that this current version fits my need at the moment.

Feel free to extend and enhance it. Let me know if you create a new version so that I can enjoy that as well. 🙂

You can download the file here.

UPDATE 07-15-2006: I have updated the template to support Enums. I also created a console app so that you can call this during your build process.

Hello world!

Welcome to my blog, finally. For those who don’t know me, my name is Thomas Jaeger and I will be posting about software development and architecture as a whole using .Net and the latest tools and automation processes to make life easier.

One of my talents is being able to motivate and inspire other programmers to create the next great thing. Many programmers do not relies that they posses a gift. A gift to create, to build something from nothing. The urge to create is what many programmers love.

Anyways, as time permits I will write more about my experiences and thoughts. Enjoy!