Search code examples
c#compiler-constructionprogramming-languagesexport-to-xml

C# to XML or Prefix-Notation


Maybe this is kind of a pie-in-the-ski dream/question. Does anyone know of a tool that will produce XML or prefix-notation (lispy) -- that includes documentation comments from C# source code? It seems like this would be useful to a number of documentation generators, or static analysis tools, or whatever.

Admittedly this is a middle-ware kind of tool, and probably could be done via a compiler-generator like Antlr. However, someone might have scratched an itch and produced something along these lines... eh?

Edit: To Clarify: "that includes documentation comments from C# source code"

I add this to distinguish that an AST probably won't include comments (though Antlr has a 'channel' concept that can stream comments).

Edit: As far what to extract: Well basically the AST, with Comments, but in a form that is reusable, ie Lispy or XML would be fine. But it would have to be complete so that if one re-purpose doesn't need information another process could still benefit from its inclusion.

Hope that helps.

L-


Solution

  • Okay, now it's clearer that you want a full AST, there's nothing in the standard tools from MS yet. However, the C# compiler team are currently working on "Roslyn" aka "compiler as a service". Preview builds are due very soon - at which point it should become clearer whether or not this supports what you're after.

    It's unknown at the moment whether Roslyn will be available just as part of the .NET framework or whether it'll only ship with some SKUs of Visual Studio - but it may well end up being more affordable than some other alternatives.


    Original answer

    This is already part of the language and normal tools - in Visual Studio, just go to Project Properties / Build / Output and enable the checkbox with "XML Documentation File". Pick the file to write the docs to, and away you go.

    Building readable HTML from that is slightly trickier; Sandcastle will do this, but needs a helper project - Sandcastle Help File Builder to turn it into a more manageable task. It's fairly flexible in what it produces though - for an example, you could look at the API documentation for Noda Time which is generated with Sandcastle.

    Additionally, if you're building a class library for others to use, if you ship the XML alongside the DLL and it has the same name (just with a .xml suffix instead of .dll), Visual Studio will use it to give your users tooltips when they use your types, methods etc.