Hi boys and Girls,

Quick question I cannot seem to find the answer to:

Why use CodeDOM to generate a class over say saving the structure of your code as text to a notepad and renaiming it to .cs? or just save it as a .cs file outright?

Why go through all the effort of using CodeDOM if it will be easier to read programmatically i.e.

string = "using bar;"

SaveToFile(file, string);

string = "namespace bla"


string = "{" 



anyone care to venture?

Kind Regards

p.s. Excuse the pseudo code.

Edited by Krefie: Made it more readable

2 Years
Discussion Span
Last Post by gusano79
  • Prevent syntax errors
  • Target multiple .NET languages

Is this an assigment? Detailed explanation left as an exercise for the reader.


Hi Gusano79,

No it is actually one of my pet projects. Thing is I always have to create new object classes for 3 tier programming, so I thought I would cycle through each table in the database and each field and then create the classes with their methods and properties with CodeDOM. So it would matter if the database has 60 tables with 200 fields, it'll create everything dynamically..

Just wanted to know if codeDOM is worth the effort, otherwise I can just create a text file with the class structure(methods and properties) and save it as .cs...


I'd say it's worth it just for the reduced risk of making unintentional mistakes while generating code.

But if you're working in .NET, the Entity Framework already does most of what you'll want.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.