reference to generic type in XML code comment [duplicate]

北城余情 提交于 2020-01-22 04:57:07

问题


As I know, in a XML comment for a C# type/method, it is possible to reference a generic type in a tag like so:

///<see cref="name.space.typename&lt;T&rt;(paramtype)">

But I think, there was another syntax, which is less clumsy? Something, to get rid of those html entities '<'? I cannot find it right now. Can somebody help?


回答1:


Here's a good article on documentation: C# XML documentation comments FAQ

The compiler team decided to improve this by allowing an alternate syntax to refer to generic types and methods in doc comments. Specifically, instead of using the open and close angle-brackets it’s legal to use the open and close curly braces. The example above would then become:

class Program
{
    /// <summary>
    /// DoSomething takes a <see cref="List{T}"/>
    /// </summary>
    void DoSomething(List<int> al) { }
}

So, in your case:

///<see cref="name.space.typename{T}( paramtype )" />

Edit: Link above is kind-of broken; shows the raw html. Leaving the link for now. Here are a couple of newer references from Microsoft:

  • XML Documentation Comments (C# Programming Guide)
  • Documenting your code with XML comments



回答2:


Use curly brackets:

///<see cref="name.space.typename{T}(paramtype)">


来源:https://stackoverflow.com/questions/5030091/reference-to-generic-type-in-xml-code-comment

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