使用 C# 属性和文档

发布于 2024-11-30 19:33:47 字数 733 浏览 0 评论 0原文

让我们考虑以下源代码。

/// <summary>
/// This is a method I would like to document
/// </summary>
/// <param name="param1">Description for param1</param>
/// <param name="param2">Description for param2</param>
/// <returns>See Type1</returns>
[Api(1)]
public Type1 Method1(
    [ApiParam(Name = Names.Name1, IsRequired = true)] string param1
     string param2
    ) {
    ...
    }

/// <summary>
/// This is a method I would like NOT to document
/// </summary>
public void Method2() {
    ...
    }

我的问题是,你们如何处理代码经常使用 C# 属性但文档生成工具似乎不支持它们的事实。

在上面的示例中,我想生成帮助文件,其中仅包含用 ApiAttribute 标记的方法(和类型)。例如。

例如,对于 Doxygen,解决方案似乎使用单独的物理文件夹。

Let's consider the following source code.

/// <summary>
/// This is a method I would like to document
/// </summary>
/// <param name="param1">Description for param1</param>
/// <param name="param2">Description for param2</param>
/// <returns>See Type1</returns>
[Api(1)]
public Type1 Method1(
    [ApiParam(Name = Names.Name1, IsRequired = true)] string param1
     string param2
    ) {
    ...
    }

/// <summary>
/// This is a method I would like NOT to document
/// </summary>
public void Method2() {
    ...
    }

My question is how do you guys deal with the fact that the code often uses C# attributes but documentation generate tools seem not support them.

In the above example I would like to generate help file(s) which would include only methods (and types) which are marked with the ApiAttribute. For example.

For Doxygen, for example, the solution seems to use separate physical folders.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揪着可爱 2024-12-07 19:33:47

属性应该用作元数据装饰器(并且在有限的情况下向特定代码段添加功能),并且不应该真正对文档做出决定;这就是文档的用途。如果您有一个公开 API 的库,您应该为 API 本身使用外观类,它可以(并且可能应该)位于不同的文件夹中。从该文件夹生成文档,然后就可以开始了。另外,通过分离关注点,它可以为你省去很多麻烦。

Attributes should be used as a metadata decorator (and in limited cases add functionality to specific pieces of code), and shouldn't really be making decisions on documentation; that's what documentation is for. If you have a library that exposes an API, you should be using facade classes for the API itself, which can (and likely should) be in a different folder. Generate the doc off that folder, and you're good to go. Plus it will save you a lot of headache by separating concerns.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文