Wii*_*axx 5 c# documentation nullable optional-parameters visual-studio
在为我的程序编写 XML 文档时,我在记录此方法时遇到了一个问题:
internal void MethodB(int i, DateTime? date = null);
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是特定于参数的date
。正如您所看到的,它是可选的并且可以为 null。以下是我尝试记录此方法的方法:
/// <summary>
/// This method uses <see cref="MethodB(Int32, System.DateTime)"/> internally
/// todo some stuff.
/// </summary>
Run Code Online (Sandbox Code Playgroud)
具体来说,我收到一条编译器警告,表明无法解析cref的值。
如何修复 XML 文档注释,使其在编译时不会出现此警告?
尝试指示该System.DateTime
参数可为空:
using System;
/// <summary>
/// This method uses <see cref="MethodB(Int32, DateTime?)"/>
/// internally to do some stuff...
/// </summary>
Run Code Online (Sandbox Code Playgroud)
编辑:正如OP @WiiMaxx 后来发现的那样,还有一种替代语法:
/// <summary>
/// This method uses <see cref="MethodB(Int32, Nullable{DateTime})"/>
/// internally to do some stuff...
/// </summary>
Run Code Online (Sandbox Code Playgroud)
另请注意,特定于语言的类型int
可以用作系统类型的替代Int32
(有些人认为这int
是更好的选择):
/// <summary>
/// This method uses <see cref="MethodB(int, DateTime?)"/>
/// internally to do some stuff...
/// </summary>
Run Code Online (Sandbox Code Playgroud)
请参阅: int 还是 Int32?我应该关心吗?字符串和字符串有什么区别?。
最后,无论 XML 文档注释是否包含Int32
或int
,Int32
都会出现在生成的文档中(这不是特定于编程语言的)。
归档时间: |
|
查看次数: |
2272 次 |
最近记录: |