How to add items enclosed by < > to documentation comments

孤者浪人 提交于 2019-12-10 13:17:37

问题


I am trying to write documentation comments however I have a problem.

/// <summary>
/// Inserts an element into the System.Collections.Generic.List<T> at the specified
/// index.
/// </summary>

When I reach the <T> Visual studio thinks I am trying to add another tag. what is the correct way to add comments like that (and if I could make them click able in the generated help text that would be a extra bonus)


回答1:


C# documentation comments are XML, so change your < and > to &lt; and &gt;.

What you're better off doing, though is, is using the <see> tag to insert a hyperlink. In a <see> tag, change <T> to {T}:

/// <summary>
/// Inserts an element into the <see cref="List{T}"/> at the specified
/// index.
/// </summary>

(Note that the cref attribute is syntax-checked by the compiler, unlike ordinary text.)




回答2:


escape the xml entities.

Change <T> into &lt;T&gt;



回答3:


I believe this would be of help for you: C# XML documentation comments FAQ.




回答4:


Since the comment is xml you can use appropriate escape sequences for xml:

/// Inserts an element into the System.Collections.Generic.List&lt;T&gt; at the specified 



回答5:


You need to use the proper char codes: &lt; and &gt;.

You would want to surreound the whole System.Collections.Generic.List<T> in a <see cref="..."/> tag.

I actually had to use the above mentioned tags to correctly write this answer :)



来源:https://stackoverflow.com/questions/2367357/how-to-add-items-enclosed-by-to-documentation-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!