Divil
Well-known member
- Joined
- Nov 17, 2002
- Messages
- 2,748
What is CodeDom?
CodeDom is a system for representing source code elements with a hierarchical structure of classes. While CodeDom cannot hope to be able to wrap every feature of every language, it manages to be pretty comprehensive.
The documentation on CodeDom is a little sparse of examples, and it is not often clear how to use the classes to construct a representation of code. Writing the code to generate even the simplest of structures tends to be quite verbose, in fact.
Saying that, CodeDom is great. The Windows Forms Designers use it to build the code for recreating the objects you configure on your forms at design time, then use a CodeGenerator for the language you are working in (VB.NET, C# or JScript.NET) to turn that "CodeDom Graph" in to actual syntax.
Covering CodeDom completely is a difficult subject and beyond the scope of this sample, but I knocked this up just to demonstrate what it does. From the constructor of the form I populate a simple CodeDom graph - one namespace, one class, one method, and a couple of variable declarations and assignments in the method. You can then press one of three buttons to have the CodeDom graph generate source code in the three .NET languages using the appropriate CodeGenerators.
CodeDom is a system for representing source code elements with a hierarchical structure of classes. While CodeDom cannot hope to be able to wrap every feature of every language, it manages to be pretty comprehensive.
The documentation on CodeDom is a little sparse of examples, and it is not often clear how to use the classes to construct a representation of code. Writing the code to generate even the simplest of structures tends to be quite verbose, in fact.
Saying that, CodeDom is great. The Windows Forms Designers use it to build the code for recreating the objects you configure on your forms at design time, then use a CodeGenerator for the language you are working in (VB.NET, C# or JScript.NET) to turn that "CodeDom Graph" in to actual syntax.
Covering CodeDom completely is a difficult subject and beyond the scope of this sample, but I knocked this up just to demonstrate what it does. From the constructor of the form I populate a simple CodeDom graph - one namespace, one class, one method, and a couple of variable declarations and assignments in the method. You can then press one of three buttons to have the CodeDom graph generate source code in the three .NET languages using the appropriate CodeGenerators.