I use Microsoft Visual Studio 2012. When I put code examples into XML comments of C# classes/methods, I wonder: how will user that references my assemblies see that code example?
I tried to reference my own assembly, and the only way I found was: to look at assembly.xml file. Can I settle Visual Studio or anything else to see those code examples?
Here is what I put into comments:
/// <summary>
/// This is my method example
/// </summary>
/// <example>
/// <code>
/// // Here is my code example. Call my method like this:
/// const int a = 10;
/// MethodExample(a);
/// </code>
/// </example>
public static void MethodExample(int parameter)
{
}
Here is what I get in IntelliSense:
Here is what I get in Object Browser:
Here is what I get in assembly.xml file:
What I'd like to get: see code examples in Object Browser and IntelliSense.
The syntax for adding XML comments in your code is triple slashes /// followed by one of the supported XML tags.
C# documentation comments use XML elements to define the structure of the output documentation. One consequence of this feature is that you can add any valid XML in your documentation comments. The C# compiler copies these elements into the output XML file.
If you are using Eclipse IDE you can comment out lines in an XML file by highlighting them and press Ctrl+Shift+c.
C# Multi-line Comments Multi-line comments start with /* and ends with */ . Any text between /* and */ will be ignored by C#.
A number of XML comment tags appear in IntelliSense only as child elements of other tags. These tags, known as ChildCompletionList tags, are: c, code, example, list, listheader, para, paramref, see and see also.
/// <summary>
/// MethodExample the function that does it all...
/// <example>
/// <code>
/// <para/>// Here is my code example. Call my method like this:
/// <para/>const int a = 10;
/// <para/>MethodExample(a);
/// </code>
/// </example>
/// </summary>
If your not seeing XML commments in IntelliSense or they're not updating after you edit them try:
Not seeing: be sure everything is enclosed in the <summary> element. ref: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/xmldoc/recommended-tags
Not updating: close & reopen solution (this seems to work pretty consistently)
VS Ent 2019 (16.10.4)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With