views:

337

answers:

2

I have the requirement to generate and read some CS classes with a DSL, I have adopted one method for reading the CS files using EnvDTE and my colleague has used CodeDom to produce the CS files.

Is it just sugar or is there a big difference between...

codeClass.AddFunction("DoSomething", vsCMFunction.vsCMFunctionFunction, "bool");

and

     CodeMemberMethod membMethod = new CodeMemberMethod();
        membMethod.Attributes = MemberAttributes.Static;
        membMethod.ReturnType = new CodeTypeReference("bool");
        membMethod.Name = "DoSomething";

I subjectively prefer the EnvDTE but do not know what the 'real' difference is.

Info: C#, Visual Studio 2010

A: 

Using EnvDTE, I'm not sure you can manipulate AST like you can with CodeDOM. I would go with CodeDOM, or NRefactory from SharpDevelop project, which is another open source C# parser/generator.

Romain Verdier
Thank you for your reply, I have not come across the acronym AST before?
Phill Duffy
AST stands for Abstract Syntax Tree, which is basically a tree structure that represents the code and allows you to manipulate it in a (more or less) strongly typed way. http://en.wikipedia.org/wiki/Abstract_syntax_tree
Romain Verdier
A: 

CodeDOM does not have a way to read source code to produce an AST. If all you need to do is generate C#, then CodeDOM ships with the .NET framework and so your application would not require Visual Studio to be installed.

Olivier Dagenais