Reuse XML comments with <see cref> in token files or in included files
Hello,
I would like to reuse some blocks of XML comments that are the same for a few functions. Example 1:
Public Class MyClass
''' <summary>
''' Return the function name of the class <see cref="MyClass">.
''' </summary>
''' <returns>The function name</returns>
Public Function Func1() As String
Return "Func1"
End Function
''' <summary>
''' Return the function name of the class <see cref="MyClass">.
''' </summary>
''' <returns>The function name</returns>
Public Function Func2() As String
Return "Func2"
End Function
End Class
I tried to use token files and included files in order to be able to reuse the XML comments. Exemple 2:
''' <summary>
''' <token>FunctionSummary</token>.
''' </summary>
''' <returns>
''' <token>FunctionReturnedValue</token>
''' </returns>
Or exemple3:
''' <summary>
''' <include file='C:\Comments.xml' path='Comments[@name="FunctionSummary"]/*' />
''' </summary>
''' <returns>
''' <include file='C:\Comments.xml' path='Comments[@name="FunctionReturnedValue"]/*' />
''' </returns>
My issue is that if I use token files or included files the <see cref> are not links inside the *.CHM file documentation. In the exemple 2 or 3 with <see cref="MyClass">, MyClass is displayed with bold font only. However in the exemple 1 with <see cref="MyClass">, MyClass is displayed as a link which references MyClass documentation page.
Do you know if it is possible to circumvent my issue?
Thanks for helping.
Cheers,
Nicolas
Remember that it's the compiler that fully qualifies the cref values. If included via a token or an include element, that doesn't happen. As such, you'll need to fully qualify the target IDs with the prefix and namespace in the token file or the include file. For example:
Return the function name of the class <see cref="T:MyNamespace.MyClass" />
Hello Eric,
Thank you very much for helping and for your quick answer.
So if I understand correctly, it possible to fully qualify a cref inside a token or an include element, if its namespace is prefixed with T:.
I tried to add the T: before the namespace MyTestNamespace. The link that references MyTestClass documentation page is not displayed inside the CHM. It is rather displayed as shown by the attached image with title "MyTestClass.Func4 Method" (see the image below).
What I would like is a link, as shown by the attached image with title "MyTestClass.Func2 Method" (see the image below).
It seems impossible to do so with an include element or a token. The only way it works, it is like Func2 (see the code below).
Do you have any idea?
Thanks,
Nicolas
Namespace MyTestNamespace
''' <summary>
''' This is a class for testing some functions of <see cref="MyTestNameSpace.MyTestClass" />with <see cref="MyTestNameSpace.MyTestClass" /> tag.
''' </summary>
Public Class MyTestClass
''' <summary>
''' Return the function name of the class <see cref="T:MyTestNameSpace.MyTestClass" />.
''' </summary>
''' <returns>The function name</returns>
''' <remarks>
''' Return the function name of the class <see cref="T:MyTestNameSpace.MyTestClass" />.
''' </remarks>
Public Function Func1() As String
Return "Func1"
End Function
''' <summary>
''' Return the function name of the class <see cref="MyTestNameSpace.MyTestClass" />.
''' </summary>
''' <returns>The function name</returns>
''' <remarks>
''' Return the function name of the class <see cref="MyTestNameSpace.MyTestClass" />.
''' </remarks>
Public Function Func2() As String
Return "Func2"
End Function
''' <summary>
''' <include file='Comments.xml' path='Comments/Comment[@name="SeeCrefWithT"]/*' />
''' </summary>
''' <returns>The function name</returns>
''' <remarks>
''' <include file='Comments.xml' path='Comments/Comment[@name="SeeCrefWithT"]/*' />
''' </remarks>
Public Function Func3() As String
Return "Func3"
End Function
''' <summary>
''' <include file='Comments.xml' path='Comments/Comment[@name="SeeCrefWithoutT"]/*' />
''' </summary>
''' <returns>The function name</returns>
''' <remarks>
''' <include file='Comments.xml' path='Comments/Comment[@name="SeeCrefWithoutT"]/*' />
''' </remarks>
Public Function Func4() As String
Return "Func4"
End Function
''' <summary>
''' <token>SeeCrefWithT</token>
''' </summary>
''' <returns>The function name</returns>
''' <remarks>
''' <token>SeeCrefWithT</token>
''' </remarks>
Public Function Func5() As String
Return "Func5"
End Function
''' <summary>
''' <token>SeeCrefWithoutT</token>
''' </summary>
''' <returns>The function name</returns>
''' <remarks>
''' <token>SeeCrefWithoutT</token>
''' </remarks>
Public Function Func6() As String
Return "Func6"
End Function
End Class
End Namespace
The IDs without the prefix will never work. You must prefix the ID with the proper member type character. In addition, VB.NET projects appear to prefix all member IDs with the root namespace defined in the project properties. Also, XML and the member IDs are case sensitive. You've got an uppercase "S" in "Namespace" which doesn't match the code so it will fail all of those. The proper ID to use is: T:ClassLibrary1.MyTestNamespace.MyTestClass where ClassLibrary1 is the root namespace defined in the project properties.
Hello Eric,
Wonderfull! Thank you very much for your explaination and for sending me the documentation about "Member ID Strings". Sorry for the typo, I didn't see that "MyTestNameSpace" hadn't a small "s": "MyTestNamespace".
The following works now perfectly:
Return the function name of the class <see cref="T:MyRootNamespace.MyTestNamespace.MyTestClass" />.
MyRootNamespace is the root namespace in the VB.NET project properties.
MyTestNamespace is the namespace that contains MyTestClass.
MyTestClass is the referenced class in the documentation.
By using an included file, I am now trying to create a link that references to System.Collections.Generic.IEnumerable(Of T).
It doesn't seem possible to do so even by prefixing with T.
The code is the following:
''' <summary>
''' Loop a <see cref="System.Collections.Generic.IEnumerable(Of String)" /> and return each element in a concatenated String.
''' </summary>
''' <returns>Each element in a concatenated String</returns>
''' <remarks>
''' Loop a <see cref="System.Collections.Generic.IEnumerable(Of String)" /> and return each element in a concatenated String.
''' </remarks>
Public Function Func09(objCollection As System.Collections.Generic.IEnumerable(Of String)) As String
Dim strFunc09 As String = ""
For Each strFunc As String In objCollection
strFunc09 = String.Concat(strFunc09, strFunc)
Next
Return strFunc09
End Function
''' <summary>
''' <include file='Comments.xml' path='Comments/Comment[@name="SeeCrefWithIEnumerable"]/*' />
''' </summary>
''' <returns>Each element in a concatenated String</returns>
''' <remarks>
''' <include file='Comments.xml' path='Comments/Comment[@name="SeeCrefWithIEnumerable"]/*' />
''' </remarks>
Public Function Func10(objCollection As System.Collections.Generic.IEnumerable(Of String)) As String
Dim strFunc10 As String = ""
For Each strFunc As String In objCollection
strFunc10 = String.Concat(strFunc10, strFunc)
Next
Return strFunc10
End Function
Comments.xml file is referenced by Func10. Here is a part of this file:
<Comment name="SeeCrefWithIEnumerable">
<para>
Loop a <see cref="T:System.Collections.Generic.IEnumerable(Of T:System.String)" /> and return each element in a concatenated String.
</para>
</Comment>
I also tried this without success:
Loop a <see cref="T:System.Collections.Generic.IEnumerable(Of String)" /> and return each element in a concatenated String.
The result is below. You can see that without an included file everything is OK (Func09) but with one it isn't (Func10).

What is wrong now?
Thanks alot,
Nicolas
Ignore what I said before if you read it. You need to use the encoded form which is a back tick followed by a number that represents the number of type parameters. The easiest way to see what the ID should look like is to take a look at the ID generated in the XML comments file when you include the comments normally.
Hello Eric,
Thank you very much! I didn't know.
I looked the XML file of my project in <project directory>\bin\Debug. The ID was:
T:System.Collections.Generic.IEnumerable`1
It works perfectly by replacing it in my Comments.xml file.
I will ask you another question later today or tomorrow. I have some verifications to do before.
Thanks again,
Nicolas