System.CodeDom articles on the web - Utility programming heaven

I've always loved writing to solve “types of problems” as opposed to any single problem.  I've always been intrigued by the CodeDom namespace, but also intimidated by it's size and apparant complexity.  Anyway, here are some resources to look deeper into the namespace, and some ideas of the potential...

Some possibilites taken from OnDotNet.com:

  • Query the metadata about your stored procedures to build a class to handle parameter binding.
  • Query the manifest of an assembly to build a class to unit-test every function.
  • Build standard boilerplate code for templates in every language your group uses.
  • Write sample code once, and allow the reader to view it in any language they choose.
  • Define your own template grammar and parse it to produce code in any language.
  • Generate code in a language that you are not familiar with, but are trying to learn, to compare to a language that you already know.

Also, DevX has a great article by A. Russell Jones that wraps it up nicely:

What's the Point?
You can use these techniques to write wizards to reduce repetitive coding tasks, to generate GUI code, or to emit code customized by users. For example, Microsoft uses the CodeDOM in Visual Studio to create abstract representations of typed DataSet classes that use the field names and types from a table or query specified by a developer. They then emit the code for the typed DataSet in the same language that the user selected for the project.

Finally, CodeDOM functionality isn't limited to generating source code; it also contains methods to compile code, so you can compile your generated code to an assembly at runtime. The combination provides a powerful way to create, compile, and execute customized code created at runtime as well as design time.

The article starts with a chart explaining the CodeDom process:

1.

Create a namespace.

2.

Import namespaces, such as System.Text or System.Drawing.

3.

Create a class and add it to the namespace.

4.

Create member fields for the class, defining the name and type for each field.

5.

Create methods and properties

6.

Populate each method or property with code by adding statements to it.

7.

Add the method or property to the class.

8.

Create an appropriate code provider object.

9.

Use the code provider's CreateGenerator method to obtain a CodeGenerator object.

10.

Call one of the generator's GenerateCodeFrom... methods to emit the code.

 

[read more here]

Print | posted on Wednesday, August 11, 2004 10:33 AM

Feedback

# re: System.CodeDom articles on the web - Utility programming heaven

left by Kim at 8/16/2004 10:24 AM Gravatar
Hey there,
It looks like I could learn a lot more from your blog... if I could understand a tenth of it! But I know Spyros will enjoy looking at it and learning new things.
Hope the ride back for you guys went well and the children bombarded you with hugs and kisses!
Of course you can't take the hug back... after my diatribe... it was greatly appreciated! I just need to get over my hugging phobia.
Must go flea marketing in St. Germain now, and see what kind of goodies they have.
If you feel like it, Spyros' blog is www.xanga.com/spyros

# Great article.

left by Jason at 5/27/2005 8:14 PM Gravatar
Your article is great.
Thanks.
Title  
Name
Email (never displayed)
Url
Comments   
Please add 2 and 6 and type the answer here: