跳到正文
Skillpedia
技术文档40k · #7152

csharp-docs

它能做什么

这个智能体可以帮你为 C# 代码添加文档注释,让代码更容易理解。它会确保注释遵循最佳实践,让其他程序员(或将来的你自己)都能看懂代码的作用。

适用场景

  • ✓在编写会与他人共享的 C# 代码时。
  • ✓在创建其他开发者会使用的库或 API 时。
  • ✓为了提高你自己 C# 代码的清晰度和可维护性。

技能链接

https://github.com/github/awesome-copilot/blob/main/skills/csharp-docs/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/csharp-docs/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请按照最佳实践,为我的 C# 代码中的公共成员和内部成员添加 XML 文档。”

每周 5 个新技能,1 分钟读完。

工作原理

这个智能体会分析你的 C# 代码,并在合适的位置插入 XML 注释(`///`),例如类、方法和属性的前面。它会使用 `<summary>`、`<remarks>` 和 `<param>` 等特定标签,说明代码的用途、细节和参数。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

C# Documentation Best Practices

  • Public members should be documented with XML comments.
  • It is encouraged to document internal members as well, especially if they are complex or not self-explanatory.

Guidance for all APIs

  • Use <summary> to provide a brief, one sentence, description of what the type or member does. Start the summary with a present-tense, third-person verb.
  • Use <remarks> for additional information, which can include implementation details, usage notes, or any other relevant context.
  • Use <see langword> for language-specific keywords like null, true, false, int, bool, etc.
  • Use <c> for inline code snippets.
  • Use <example> for usage examples on how to use the member.
    • Use <code> for code blocks. <code> tags should be placed within an <example> tag. Add the language of the code example using the language attribute, for example, <code language="csharp">.
  • Use <see cref> to reference other types or members inline (in a sentence).
  • Use <seealso> for standalone (not in a sentence) references to other types or members in the "See also" section of the online docs.
  • Use <inheritdoc/> to inherit documentation from base classes or interfaces.
    • Unless there is major behavior change, in which case you should document the differences.

Methods

  • Use <param> to describe method parameters.
    • The description should be a noun phrase that doesn't specify the data type.
    • Begin with an introductory article.
    • If the parameter is a flag enum, start the description with "A bitwise combination of the enumeration values that specifies...".
    • If the parameter is a non-flag enum, start the description with "One of the enumeration values that specifies...".
    • If the parameter is a Boolean, the wording should be of the form "<see langword="true" /> to ...; otherwise, <see langword="false" />.".
    • If the parameter is an "out" parameter, the wording should be of the form "When this method returns, contains .... This parameter is treated as uninitialized.".
  • Use <paramref> to reference parameter names in documentation.
  • Use <typeparam> to describe type parameters in generic types or methods.
  • Use <typeparamref> to reference type parameters in documentation.
  • Use <returns> to describe what the method returns.
    • The description should be a noun phrase that doesn't specify the data type.
    • Begin with an introductory article.
    • If the return type is Boolean, the wording should be of the form "<see langword="true" /> if ...; otherwise, <see langword="false" />.".

Constructors

  • The summary wording should be "Initializes a new instance of the <Class> class [or struct].".

Properties

  • The <summary> should start with:
    • "Gets or sets..." for a read-write property.
    • "Gets..." for a read-only property.
    • "Gets [or sets] a value that indicates whether..." for properties that return a Boolean value.
  • Use <value> to describe the value of the property.
    • The description should be a noun phrase that doesn't specify the data type.
    • If the property has a default value, add it in a separate sentence, for example, "The default is <see langword="false" />".
    • If the value type is Boolean, the wording should be of the form "<see langword="true" /> if ...; otherwise, <see langword="false" />. The default is ...".

Exceptions

  • Use <exception cref> to document exceptions thrown by constructors, properties, indexers, methods, operators, and events.
  • Document all exceptions thrown directly by the member.
  • For exceptions thrown by nested members, document only the exceptions users are most likely to encounter.
  • The description of the exception describes the condition under which it's thrown.
    • Omit "Thrown if ..." or "If ..." at the beginning of the sentence. Just state the condition directly, for example "An error occurred when accessing a Message Queuing API."
常见问题

C# 中的 XML 注释是什么?

这是 C# 代码中一种特殊的注释,使用 XML 标签(比如 `<summary>`)来描述代码的作用。工具可以利用这些注释自动生成文档。

为什么要为内部成员添加文档?

虽然不是必须的,但为内部成员添加文档有助于解释复杂或不直观的代码部分,让维护者更容易理解。

什么是 `<inheritdoc/>`?

这是一个标签,用来告诉编译器从父成员(比如基类或接口)复制文档到当前成员。当行为相同时,这样可以避免重复编写代码。

详情

作者的原始描述

Ensure that C# types are documented with XML comments and follow best practices for documentation.

repo: github/awesome-copilot

热度

GitHub 星标
40k
排名
#7152
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能