在为我的程序编写 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文档注释是否包含Int32
或int
,生成的文档中都会出现Int32
(不是编程语言- 具体)。
关于c# - 在 XML 文档中使用 <see cref =""/> 和可选的可为空参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26486308/