您可以使用 Nameof 或其他技术将过程名称动态嵌入代码注释中吗?

Kei*_*ard 8 c# vb.net

如果 SampelSubName 的名称发生更改,以下注释行将变得不准确。'这是关于 SampleSubName 的代码注释。

Bra*_*ith 10

如果您使用 Visual Studio 2015 或更高版本,使用内置重构工具重命名方法也会重命名 XML 注释中的所有引用。您可以使用标签引用方法名称<see>,例如

/// <summary>
/// This is a code comment about <see cref="SampelSubName" />.
/// </summary>
public void SampelSubName() { }
Run Code Online (Sandbox Code Playgroud)


Soo*_*nts 10

另一种技术。Visual Studio IDE 支持 XML 注释,如下所示:

/// <remarks>This is a code comment about <see cref="SampelSubName"/>. </remarks>
Run Code Online (Sandbox Code Playgroud)

如果您编写这样的注释并将 SampelSubName 重命名为其他名称,IDE 也会更新这些cref=引用。

有关 XML 注释的更多信息,请参阅这篇文章