0

I have an API project that uses .Net's XML documentation. This results in MyApp.dll getting a MyApp.xml file with all the code comments, which looks something like this:

<?xml version="1.0"?>
<doc>
    <assembly>
        <name>MyApp</name>
    </assembly>
    <members>
        <member name="T:MyApp.MyNamespace.MyClass">
            <summary>Description of class</summary>
        </member>
        <member name="M:MyApp.MyNamespace.MyClass.MyGenericMethod``1(``0)">
            <summary>Description of method</summary>
            <typeparam name="T">Description of generic type</typeparam>
            <param name="paramName">Description of parameter.</param>
            <returns>Description of what this returns.</returns>
        </member>
        ...
    </members>
</doc>

I have typeof(MyClass) and from that I want to extract all this documentation. I know that I can use SandCastle to build an external .CHM help, but this needs to be part of the application that uses the API.

I want to be able to use XPath $"//member[@name='key']" to get the relevant XmlNode in the documentation file.

It's fairly easy to look up typeof(MyClass) or even use typeof(MyClass).GetMembers() to get the members, but there doesn't appear to be an easy way to get the name used in the XML documentation. For a type I can use $"T:{typeof(MyClass).FullName}", but for MemberInfo this is a great deal more complicated, especially for generics. Every parameter must be included in the lookup key.

I can read the MemberInfo.MemberType and parse all the generic and regular parameters, but that seems like a lot of work for something .Net must already be doing to build the XML file in the first place.

So, I have the MemberInfo for MyGenericMethod - how do I get "M:MyApp.MyNamespace.MyClass.MyGenericMethod``1(``0)" from that?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Keith
  • 150,284
  • 78
  • 298
  • 434
  • Maybe give SAX parser a try ? would that of some help here ? – ZygoteInit Apr 13 '16 at 10:06
  • @ZygoteInit it's really not parsing the XML that's the problem - I have a bunch of options there (that's why I haven't tagged this as XML). The problem is that the comments XML (or any other format that I turn it into) refers to member names by a complex `string` key that I can't easily parse from the `MemberInfo`. – Keith Apr 13 '16 at 10:09

0 Answers0