Did you ever wonder how Microsoft creates those typed DataSet classes in Visual Studio .NET? Did this article give you ideas for how you might use CodeDOM to create your own language-independent code generator functionality? If so, what do you plan to use it for? If not, do you just not need the capability, or do you think it's not useful. Let us know in the vb.dotnet.technical newsgroup.
The CodeDOM namespace contains classes that abstract the idea of code. After defining code in this abstract manner, you can use a language-specific CodeProvider class to generate code in any .NET language from that single abstract CodeDOM representation.
by A. Russell Jones
May 16, 2003
he .NET framework is replete with nooks and crannies of functionality that are amazingly powerful, but sorely underdocumented. One of those lesser-known capabilities lies in the CodeDOM namespace. This namespace is the .NET language equivalent of the HtmlTextWriter and XmlTextWriter classes, but rather than using the classes to write HTML or XML, you use the classes and methods in the CodeDOM namespace to write .NET code. One of the most interesting things about CodeDOM is that it's completely language-agnostic. The CodeDOM namespace abstracts most (not allat least, not yet) types of code operations into an object model. You create object instances that represent namespaces, classes, fields, methods, properties, parameters, references to various types, and so forth.
Each .NET language has a special code provider class. For VB.NET, the code provider class is Microsoft.VisualBasic.VBCodeProvider. For C#, the class is Microsoft.CSharp.CSharpCodeProvider. Each provider gives you access to an object that implements the ICodeGenerator interface. The interface defines several GenerateCodeFrom... methods, one of which is GenerateCodeFromNamespace, which writes all the code for a namespace. Table 1 shows the high-level process to generate a namespace containing a class.
It's quick, easy and you get access to all the articles on DevX.
This registration/login is to allow you to read articles on devx.com. Already a member?
To become a member of DevX.com create your Member Profile by completing the form below. Membership is free!