0

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

Phill Duffy
  • 2,805
  • 3
  • 33
  • 45

2 Answers2

0

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
  • 12,833
  • 7
  • 57
  • 77
  • Thank you for your reply, I have not come across the acronym AST before? – Phill Duffy Aug 25 '09 at 13:45
  • 1
    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 Aug 25 '09 at 13:50
0

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
  • 1,482
  • 2
  • 18
  • 20