Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<example></example> XML comment tag: how to see it?

Tags:

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:

enter image description here

Here is what I get in Object Browser:

enter image description here

Here is what I get in assembly.xml file:

enter image description here

What I'd like to get: see code examples in Object Browser and IntelliSense.

like image 225
Artem Kachanovskyi Avatar asked Oct 29 '14 16:10

Artem Kachanovskyi


People also ask

How do I comment out XML code?

The syntax for adding XML comments in your code is triple slashes /// followed by one of the supported XML tags.

What is XML comments in C#?

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.

How do you comment multiple lines in POM XML?

If you are using Eclipse IDE you can comment out lines in an XML file by highlighting them and press Ctrl+Shift+c.

How do you comment out a block of code in C#?

C# Multi-line Comments Multi-line comments start with /* and ends with */ . Any text between /* and */ will be ignored by C#.


2 Answers

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>
like image 145
Past Tense Avatar answered Oct 29 '22 23:10

Past Tense


If your not seeing XML commments in IntelliSense or they're not updating after you edit them try:

  1. 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

  2. Not updating: close & reopen solution (this seems to work pretty consistently)

VS Ent 2019 (16.10.4)

like image 34
Ken747 Avatar answered Oct 29 '22 22:10

Ken747