Intellisense, Reflection and namespace.xml

So here I was working on a project that required me to look at existing .DLLs and figure out what objects, constructors, methods and properties there were.  I’m also required to return some friendly data, like the stuff you get from intellisense in Visual Studio.  I thought this was all done via System.Reflection and you can get some of it, but the friendly content just isn’t there.

After spending a ton of time looking through the System.Reflection members and looking again and looking through google and even bing I couldn’t figure out how to to get the summary and other information from the .dll using reflection.  It’s because it’s not in there.  Talk about trying to squeeze blood out of a turnip!  Where it is is in an XML document that is shipped with the Project Properties Showing the checkbox for teh XML documentation fileDLL.  It has the same name as the .DLL just with an .XML extension instead of a .DLL extension.

I was a little dumbfounded, because I never noticed this before.  I promptly built a class library and put it into a project on another machine.  I did get intellisense but I didn’t get the information that was in the comments like the summary, method or parameter information.  You only get this when the .DLL has an accompanying .XML file.  To generate this file go to Project Properties > Build and in the Output section check the box next to XML documentation file.

You end up with something that looks like:

<?xml version="1.0"?>
        <member name="T:ClassLibrary1.Class1">
            This is the class summary
        <member name="M:ClassLibrary1.Class1.Method1(System.String,System.String)">
            This is the summary for method 1
            <param name="foo1">This is foo1</param>
            <param name="foo2">This is foo2</param>

Now back to my project.  I am going to have to use a combination of reflector and parsing an xml document.  I don’t really want to be in the XML parsing business, in my travels I found someone else who’s already been through this pain and has two lines of code to get to the information that I need.

Jim Blackler wrote a blog about obtaining the inline XML C# documentation at runtime using .NET 2.0,  It’s one of those rare times that you find an article that’s a year and a half old and the information is still relevant.

basically it boils down to (the following is copied directly from his site):

XmlElement documentation = DocsByReflection.XMLFromMember(typeof(SomeExampleClass).GetProperty("ExampleProperty"));

Thanks Jim!

  • Facebook
  • DZone It!
  • Digg It!
  • StumbleUpon
  • Technorati
  • NewsVine
  • Reddit
  • Blinklist
  • Furl it!
Post a comment!
  1. Formatting options

Rss Feed
    follow me on Twitter

    Where I'm Going

    Some Writing I've Done

    Chat With Me