Skip navigation.

Spell It Out For Your UsersAll recent postsAccessible Hyperlinks In ASP.NET

HttpModule And HttpHandler Template Generator In Beta

Every time I start a new HttpModule or HttpHandler I turn to MSDN for a code skeleton. When I help out someone at the ASP.NET Forums I do the same. Finally, I thought I would put together a tool for myself and others that would do exactly that—generate bare-bones modules and handlers.

For this tool I decided to take an approach different from string.Concat or StringBuilder. I wanted to be able to create both C# and VB.NET code without pasting strings together. CodeDOM seemed to be the perfect fit:

The .NET Framework includes a mechanism called the Code Document Object Model (CodeDOM) that enables developers of programs that emit source code to generate source code in multiple programming languages at run time, based on a single model that represents the code to render...

Language-independent source code modeling can be valuable when a program needs to generate source code for a program model in multiple languages or for an uncertain target language.

With CodeDOM you don't throw together lines of code in a specific language. You are abstracted from the language altogether. You start by creating an object graph which reflects the source code structure. To this graph you add instances of classes that represent namespace imports, classes, methods and their parameters, class members, etc. Once you're done building the graph you can feed it to a code generator. The ICodeGenerator interface has a number of interesting methods. The one that produces source code from a graph is GenerateCodeFromCompileUnit. You give it a graph and a stream to write to and get source code in the language of your choice. Not too simple, but really cool.

By the way, the produced source code has a disclaimer banner at the top (emitted automatically) so feel free to remove it.

At this time the code generator does not handle asynchronous HttpApplication events. That's a can of worms of its own.

I invite you to head over to the Tools section and test drive this new online tool. Please share comments and suggestions. If there are some common tasks you add to your modules/handlers I will probably add them to the generator. As is also the case with the source code coloring tool once the code is stable I can make it available for download.

Comments

No comments yet

Emails and Notifications

Would you like to be notified when somebody responds to this post? 

TrackBacks

Sorry, TrackBacks are not allowed.

Submit your comment

Please enter only text since all HTML tags except hyperlinks will be stripped. Hyperlinks will become live links. Any comments with flaming or offensive language will be deleted. Be courteous to other posters. Thank you.

Your name (required):
Your email (optional):
Your site's URL (optional):
Enter this number
Type in the number above:
Comment (required):