Living .NET...

Musings on .NET, and the like - Manoj G [MVP, Connected Systems Developer]

May 2004 - Posts

A Look at CodeDOM

Before we get to know what actually "CodeDOM" is, lets dissect this word and understand what DOM (Document Object Model) is. DOM (a relatively old concept) is a specification provided by the World Wide Web Consortium (W3C). As of MSDN, this is what DOM is: "The W3C DOM is a platform and language-neutral interface that permits script to access and update the content, structure, and style of a document. The W3C DOM includes a model for how a standard set of objects representing HTML and Extensible Markup Language (XML) documents are combined, and an interface for accessing and manipulating them."

The important parts of this definition are "language-nuetral" and the representation of HTML/XML as a set of objects. The definition of CodeDOM is just as similar. It is just the programmatic representation of code in a language-nuetral manner. The essence of CodeDOM is to represent the source code as an object graph and use that as the basis of generating code in the language of your choice. With the help some services provided by your language compiler, you can even go to the extent of generating assemblies from this representation. Therefore the notion of dynamic code generation makes CodeDOM a very powerful concept. There are numerous areas where CodeDOM has been effectively applied :

1. First and foremost, the code-behind concept provided by ASP.NET is nothing but CodeDOM magic. At runtime, ASP.NET would essentially generate new types whose definitions are provided in the .aspx and .aspx.cs files. An instance of this generated type would be used to handle the final rendering of that page. One thing to remember here is that, to use a language in ASP.NET development, the language should (imperatively) implement a CodeDOMProvider.

2. Somewhat similar in concept to ASP.NET code-behind is the concept of compiling code represented (maybe partially) as XAML in LongHorn, the next generation Windows OS. I stumbled across this good post at longhorn blogs explaining this in detail -

3. Tools like wsdl.exe and xsd.exe use CodeDOM to generate source code from XML representations.

4. A lot of code generator tools in the market today would use CodeDOM to generate application source code from sources like Database schema , UML diagrams, XML documents and so on. So, CodeDOM can be a handsome option in your application, if you need to generate code at design time or at runtime, given disparate sources like XML or even free language text. The best part - you need not even know a language you generate code in.

I did a bit of googling myself and these are some of the good write-ups on CodeDOM:

1. A Definition of the CodeDom Abstract Language 

2. Using the CodeDOM

3. Bring the Power of Templates to Your .NET Applications with the CodeDOM Namespace

4. Microsoft .NET CodeDom Technology - Part 1

Posted: Sat, May 22 2004 15:16 by Manoj G | with no comments
Filed under:
Picks of the Week
This is one of the most useful links you can find - The complete listing of the GOF (Gang of four) patterns with downloadable C# code http://www.dofactory.com/Patterns/Patterns.aspx. You would be finding many patterns already in the MS patterns and practices site ( like Observer, MVC, Singleton), but this one is the complete set with a  taxonomical listing - a must see!
 
My second pick -  Scott Mitchell's article series on Data Structures in C#. I guess the six part series is now concluded and has been a fantastic resource. The articles cover many data structures like Trees, Graphs, Sets etc in complete depth and the writing is very lucid too.
 
Part 1: An Introduction to Data Structures
Part 2: The Queue, Stack, and Hashtable
Part 3: Binary Trees and BSTs
Part 4: Building a Better Binary Search Tree
Part 5: From Trees to Graphs
Part 6: Efficiently Representing Sets
 
Posted: Mon, May 10 2004 9:29 by Manoj G | with no comments
Filed under: