Geeks With Blogs

News Awarded Microsoft MVP C#.NET - 2007, 2008 and 2009

I am born in Bangladesh and currently live in Melbourne, Australia. I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net)and born in Bangladesh.
I am founder and Chief Executive Officer of
Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Co-founder and core developer of Pageflakes
Simplexhub, is on its mission to build a smart virtual community in Bangladesh and recently launched beta an ASP.NET MVC application written in C#.NET.

Some of My Articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Shahed Khan blog

I am glad to share my latest article at code project..

Write your own Code Generator or Template Engine in .NET

This paper demonstrates building a code generator, template engine, template parser, or template processor in .NET. The demo implementation uses cutting edge .NET technologies available today such as C# .NET 2.0, MS Provider Pattern, Enterprise Library January 2006, CodeDom etc.

If you have used Code Smith or similar tools, you may be wondering how this type of tools work. I am going to reveal in this article how easy it is to write a code generator or template engine in .NET. A template engine is a software or a software component that is designed to transform pre-formatted input into various kinds of text output. One of the major benefits of using a template engine is that it enhances productivity by reducing unnecessary reproduction of effort. For example, while designing an application, whether we implement famous design patterns (like MVC) or invent some of our own, we tend to come up with a generic structure of code throughout the application. Later on, we can write templates for the generic parts, and use template engines to quickly generate the code for us.

Template Engines makes a huge difference in development productivity. For example, if you have a database with 300 tables, and each table having at least 5 columns, imagine how long it will take to hand write all the Business Objects for all those tables. Not only this, when you complete that, you have to write your data access layer, business logic layer, and finally, the application code, and this adds up to a lot of work. However, with the help of a template engine, you can generate generic pieces of code (code that follows a similar design pattern) in minutes. You only need to write a single template, and then you simply ask the template engine to loop through each of the tables and their columns in the database, and it will generate your code for you.

So, we can all agree on how template engines can be a very helpful tool for a developer and save heaps of time. Without spending any more time on an introduction to template engines, we will jump straight into writing one.


Posted on Wednesday, September 27, 2006 10:12 PM | Back to top

Comments on this post: Write your own Code Generator or Template Engine in .NET

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Shahed Khan | Powered by: