在XML文档中,如何在可选和可空参数中使用<see cref=""/>?

5

在编写程序的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文档注释,以便它可以在没有警告的情况下编译?

1个回答

3

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

using System;

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

编辑:正如楼主@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或Int32?我需要在意吗?String和string有什么区别?

最后,无论XML文档注释中包含Int32还是int,生成的文档中将出现Int32(这并不特定于编程语言)。


任何使用类型(例如Nullable{DateTime})的内容在注释浏览器中显示时将不会显示为Nullable<DateTime>,而是显示为Nullable<T> - Neil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接