gpt4 book ai didi

c# - 有没有办法在 C# block 注释中引用 const 参数?

转载 作者:太空狗 更新时间:2023-10-29 22:57:32 25 4
gpt4 key购买 nike

在 c# block 注释中,我想说特定参数的默认值是类 const 属性。有没有办法直接引用该参数?

我想在生成的文档中显示值,或者以某种结构化方式链接到该属性。

这是我正在尝试做的一个例子:

public class Foo
{
private const int DefaultBar = 20;

///<summary>
///Does the thing.
///</summary>
///<param name="bar">Description of bar. Defaults to [[DefaultBar]]</param>
public int DoTheThing(int bar = DefaultBar)
{
return bar;
}
}

上面的 [[DefaultBar]] 是引用 DefaultBar 属性所需的任何语法。

因为它是一个常量,所以我觉得应该有一种方法可以在生成的文档中引用它,而无需手动保持它们同步。 (我不想只用 20 替换 [[DefaultBar]] 以防我想稍后将 20 更改为其他一些 int)

我看了C# "Constant Objects" to use as default parameters但该问题(和相关答案)不会显示文档。

最佳答案

您可以像使用 注释标记的任何其他代码成员一样引用常量。在您的情况下,它将是:

public class Foo
{
private const int DefaultBar = 20;

///<summary>
///Does the thing.
///</summary>
///<param name="bar">Description of bar. Defaults to <see cref="DefaultBar"/>.</param>
public int DoTheThing(int bar = DefaultBar)
{
return bar;

}
}

当您根据这些评论生成文档时,您将获得指向常量页面的链接。例如,使用 VSdocman 生成的输出(我们的产品)看起来像: enter image description here

关于c# - 有没有办法在 C# block 注释中引用 const 参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38060496/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com