c# - 在 XML 文档中使用 <see cref =""/> 和可选的可为空参数

标签 c# visual-studio documentation nullable optional-parameters

在为我的程序编写 XML 文档时,我遇到了记录此方法的问题:

internal void MethodB(int i, DateTime? date = null);

我遇到的问题特定于 date 参数。如您所见,它是可选的 以及可为空的。以下是我尝试记录此方法的方式:

/// <summary>
/// This method uses <see cref="MethodB(Int32, System.DateTime)"/> internally
/// todo some stuff.
/// </summary>

具体来说,我收到一个编译器警告,指示 cref 的值无法解决。

如何修复我的 XML 文档注释,以便它在编译时不会出现此警告?

最佳答案

尝试指示 System.DateTime 参数可为空:

using System;

/// <summary>
/// This method uses <see cref="MethodB(Int32, DateTime?)"/>
/// internally to do some stuff...
/// </summary>

编辑正如 OP @WiiMaxx 后来发现的那样,还有另一种语法:

/// <summary>
/// This method uses <see cref="MethodB(Int32, Nullable{DateTime})"/>
/// internally to do some stuff...
/// </summary>

另请注意,特定于语言的类型 int 可以用作系统类型 Int32 的替代方案(有些人会争辩说 int 更可取):

/// <summary>
/// This method uses <see cref="MethodB(int, DateTime?)"/>
/// internally to do some stuff...
/// </summary>

参见: int or Int32? Should I care?What's the difference between String and string? .

最后,无论XML文档注释是否包含Int32int,生成的文档中都会出现Int32(不是编程语言- 具体)。

关于c# - 在 XML 文档中使用 <see cref =""/> 和可选的可为空参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26486308/

相关文章:

c# - 在c#上的查询中添加参数

asp.net - 如何让 Chirpy 与 JS 和 mash.config 一起工作

c# - C#/.NET 中的图像重命名程序

documentation - sbcl:(例如)#'sb-ext:string-to-octets 的附加文档

c# - 如何为 Java、C# 和 C++ 中的一个项目的不同实现管理一份一致的文档?

javascript - 如何给JSDoc添加标签?

c# - 从内存中的视频截图,无需将视频或屏幕截图写入磁盘

c# - 在 MySQL 中插入查询后获取自动增量值

visual-studio - Nuget 发布错误 : Failed to process request. 'A client version ' 4.1.0'

c# - Html.EnumDropdownListFor 我可以按字母顺序排序吗?