Sunday, September 30, 2007

Reading XML documentation comments

So today I decided to have a little fun and see what it would take to read XML documentation comments associated with code members in assemblies that are currently loaded.  It took a little doing to get it completely correct but it's done and fully tested now (including gnarly cases involving generic parameters).

There are a few interesting uses for performing reflection on XML documentation from within a running application.  For example here is a test case that reads some of its data from its own XML comments.  It's pretty nifty.  I'm not sure I would actually recommend this usage pattern because I find embedded resources and custom attributes are sufficiently effective and robust.

What I have in mind has more to do with enhancing MbUnit Gallio reports and GUI content.  The XML documentation simply becomes another piece of metadata that you can see or manipulate.  But I won't put it past others to come up with other interesting uses of this feature.

Gotchas: The MSDN documentation regarding how member names are computed for XML documentation comments is incomplete and incorrect -- particularly as regards generic type arguments.  I think I've got it nailed though.

No comments: