Chr*_*him 6 c# documentation code-documentation
在c#块注释中,我想说的是,特定参数的默认值是类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;
}
}
Run Code Online (Sandbox Code Playgroud)
当[[DefaultBar]]以上任何是语法需要引用DefaultBar财产。
因为它是一个常量,所以我认为应该有一种方法可以在生成的文档中对其进行引用,而无需手动使其保持同步。(如果以后要更改为其他int,我不想只替换[[DefaultBar]]为)2020
我查看了C#“常量对象”作为默认参数,但是该问题(以及相关的答案)没有提出文档。
您可以像使用<see>注释标记的任何其他代码成员一样引用常量。在您的情况下,它将是:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
当您根据这些注释生成文档时,您将获得指向常量页面的链接。例如,使用VSdocman(我们的产品)生成的输出将如下所示:

| 归档时间: |
|
| 查看次数: |
1644 次 |
| 最近记录: |