Programmatically get Summary comments at runtime

A Workaround – Using reflection on Program.DLL/EXE together with Program.XML file

If you take a look at the sibling .XML file generated by Visual Studio you will see that there is a fairly flat hierarchy of /members/member.
All you have to do is get hold on each method from your DLL via MethodInfo object. Once you have this object you turn to the XML and use XPATH to get the member containing the XML documentation for this method.

Members are preceded by a letter. XML doc for methods are preceded by “M:” for class by “T:” etc.

Load your sibling XML

string docuPath = dllPath.Substring(0, dllPath.LastIndexOf(".")) + ".XML";

if (File.Exists(docuPath))
{
  _docuDoc = new XmlDocument();
  _docuDoc.Load(docuPath);
}

Use this xpath to get the member representing the method XML docu

string path = "M:" + mi.DeclaringType.FullName + "." + mi.Name;

XmlNode xmlDocuOfMethod = _docuDoc.SelectSingleNode(
    "//member[starts-with(@name, '" + path + "')]");

Now scan childnodes for all the rows of “///”
Sometimes the /// Summary contains extra blanks, if this bothers use this to remove

var cleanStr = Regex.Replace(row.InnerXml, @"\s+", " ");

Leave a Comment