【问题标题】:How to properly specify on code-documentation a function may return null on C#?如何在代码文档中正确指定函数可能在 C# 上返回 null?
【发布时间】:2019-02-28 15:37:55
【问题描述】:

我正在创建一些代码文档,并且我想正确显示如果找不到资源,该函数可能会返回 null。

我创建的带有一些代码文档的虚拟方法,以 GhostDoc 自动生成的文档为基础:

///<summary>Gets something for the specified unique identifier.</summary>
///<param name="id">Something's unique identifier.</param>
///<returns>Something if found; otherwise <c>null</c>.</returns>
private Something GetSomethingById(int id)
{ }

我目前在 Null 周围使用 XML 标记 ,但我想知道这是否是最好/正确的方法。

【问题讨论】:

  • 为什么你认为你的例子是错误的?
  • 我不是在假设它是错的,这只是我的做法。我只是想知道是否有更好的方法或更标准的方法,至少在 C# 中。
  • 您的方法有先例 - 请参阅 Microsoft 的任何在线文档。当他们引用null 时,它是使用等宽字体作为代码完成的
  • @Ian 你的意思是这样的:helixoft.com/blog/… ?

标签: c# xml documentation xml-documentation code-documentation


【解决方案1】:

为了将来参考,在对微软代码进行了一些挖掘之后,即反编译了一些 DLL,我发现它们使用的是以下标准:&lt;paramref name="sourceTimeZone" /&gt; is &lt;see langword="null" /&gt;.

该示例是从 System.TimeZoneInfo 中提取的。

不知道这是否是@Ian 在他的评论中引用的内容。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    • 1970-01-01
    • 2018-03-01
    • 2011-10-29
    相关资源
    最近更新 更多