It was discussed on SO several times, but for some reason it is extremely hard to find.
There are basically two options:
1) Use Roslyn. This is what you want if you have access to the sources. There is a great answer on this topic: How to read XML documentation comments using Roslyn
2) Parse xml documentation by yourself. Along with your binaries, you can find .xml
files with all the type descriptions. You need to turn the generation on, before having them - go to solution properties->build and specify XML documentation file
If you parse it you can retrieve any information you need. For each element, there is a separate member
tag. It has attribute name
which defines what element are you looking at. The name specified is has a prefix, which defines the type of the element - a type (T:
), a property (P:
), etc. The inners of the tag contain all the required info.
Here is an example:
<member name="T:MyNameSpace.MyTuple`2">
<summary>The summary</summary>
<typeparam name="TA">The first tuple type.</typeparam>
<typeparam name="TB">The second tuple type.</typeparam>
</member>
Please notice `2 in the end of the type name - this is because the type is generic.
Here is an example in powershell I used before:
function Get-Type-Xml-Description($typeName) {
$type = $assembly.GetTypes() | Where-Object { $_.Name -eq $typeName } | Select -First 1
if ($type -eq $null){
return $null
}
$tName = $type.FullName
$path = "T:"+$tName
$node = $xmlDocument.SelectSingleNode("//member[@name = '" + $path + "']")
return [Regex]::Replace($node["summary"].InnerText.Trim(), "\s+", " ")
}
It uses the $assembly$
to get the full name of a type, but if you know that already and you don't need to iterate over all types, you don't have to have the assembly.
Also you need to account generic type names, which have `[number of typeparams] in the end. This powershell example doesn't do this.