【问题标题】:What is compiler warning CS1723 "XML comment has cref attribute 'T' that refers to a type parameter" all about?什么是编译器警告 CS1723“XML 注释具有引用类型参数的 cref 属性‘T’”?
【发布时间】:2019-04-09 00:20:03
【问题描述】:

鉴于此代码:

/// <summary>
/// Implementations represent a configuration with a specific data 
/// type <see cref="T"/> that can be used by this application.
/// </summary>
internal interface IConfiguration<T>
{
}

我在see cref XML 元素内的T 上收到编译器警告CS1723

XML 注释具有引用类型参数的 cref 属性“T”

MS Docs 在这种情况下完全没用。我为什么要关心这个警告?这是什么原因?

【问题讨论】:

  • 我认为&lt;see cref=""&gt; 标签旨在指向另一个接口、类或其他类似的东西。在这里,您指向一个可能不存在的名为“T”的类型,因此它告诉您您的文档错误
  • 表示到另一个代码实体的链接。您希望此链接指向哪里?

标签: c# visual-studio visual-studio-2017 compiler-warnings code-documentation


【解决方案1】:

对于这种情况,您应该使用&lt;typeparamref name="T" /&gt;

https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/typeparamref

【讨论】:

  • 看,这就是我想要的(不是反对票)!谢谢。
【解决方案2】:

see cref(交叉引用)旨在指向实际类型(例如,作为生成文档中的超链接)。类型参数在这个地方没有任何意义,因为事先不知道要使用什么类型。

要文档类型参数使用

&lt;typeparamref name="name"/&gt;

【讨论】:

  • 谢谢。这就是答案。
猜你喜欢
  • 1970-01-01
  • 2021-06-10
  • 1970-01-01
  • 2012-10-17
  • 1970-01-01
  • 1970-01-01
  • 2010-10-20
  • 2011-03-19
  • 2016-12-22
相关资源
最近更新 更多