我正在尝试为我的 C# 方法上的 XML 注释构建一个列表。
我正在使用以下文档,但是其中的列表实现对我不起作用。我正在使用 Visual Studio 2008 和 .net 3.5。
http://msdn.microsoft.com/en-us/magazine/cc302121.aspx
如何在 C# 中使用 XML 注释构建列表?
这是我当前的 XML 代码。para 标签工作正常,但没有生成列表。
/// <summary>
/// Populates an entity from the database.
/// <para />
/// <list type="table">
/// <listheader>
/// <term>This method contains assumptions in the implementation of the entity:</term>
/// </listheader>
/// <item><term>Given the entity name [name]Entity (eg. [User]Entity is User), there is an
/// appropriate stored procedure created: dbo.sp[name]View (eg. dbo.spUserView).
/// <para />
/// The structure of …Run Code Online (Sandbox Code Playgroud) 我写了一个方法,例如:
/// <summary>
/// A method having xml-comments
/// This comment could be very long
/// </summary>
/// <param name="input">Input parameter</param>
/// <returns>Calculated value</returns>
int CommmentedMethod(int input) {
return Calc(input);
}
Run Code Online (Sandbox Code Playgroud)
但是当我使用这种方法时,Visual Studio(我使用的是 VS 2010)只是显示“具有 xml 注释的方法此注释可能是... ”而不是完整的文档。
有没有可以显示的选项?
更新图片:

谢谢 :-)
从 C# 类文件中提取注释相对容易(请参阅从 C# 源文件中提取文档注释),但我最近遇到了相反的问题。
我的项目有一堆从 XML 模式生成的类(通过 Microsoft 的xsd.exe)。我想写出关于这些类的 XML 文档,但我们必须经常重新创建它们。我希望能够写出注释,将它们提取到自己的 .xml 文件中,运行xsd.exe以从架构中重新创建类,然后将注释合并回来。
有什么方法可以做到这一点吗?
我有一个方法,在命名空间下抛出异常:MyApp.Domain.我在命名空间下有一些自定义异常:MyApp.Domain.Exceptions.所以我拥有的是:
using MyApp.Domain.Exceptions
using System;
namespace MyApp.Domain
{
public class SomeClass
{
///<summary>This method does some stuff</summary>
///<exception cref="MyCustomExeption">MyCustomException if x</exception>
///<exception cref="Exception">GenericException if y</exception>
public void DoStuff(){
//Does stuff
}
}
}
Run Code Online (Sandbox Code Playgroud)
我用intellisense得到了我的总结,但没有例外.我是否必须使用include并创建外部xml注释文件,因为它们位于不同的命名空间下?这两个异常都没有出现在intellisense,mycustomexception或system.exception中.
谢谢.
对于我编程使用的几乎所有语言,我经常对 XML 自动文档注释引起的工具提示宽度感到恼火。在某些情况下,我开始在每一行前面加上<para />,但随后在生成文档时我必须再次将它们过滤掉。
一个更简单的解决方案是设置这些工具提示的宽度。有人知道可以在这里使用的设置或注册表技巧吗?
我在宽屏幕上看到的示例,我认为完全无法理解:
实际上,使用<para />适用于 F#,但在 C# 中,它在每个段落之间添加了一条白线(这是有道理的,但不是我所追求的)。众所周知,<br />XML 注释中会忽略换行符。
不完全是这个想法:
但是想想这个没有空行的图像,然后你就会明白我所希望的(不顾一切;)。
如果您将鼠标悬停///<summary></summary>在 VS17 (15.6.2) 中具有xml 文档 ( ) 的某些内容(类、方法等)上,您会看到这个小弹出窗口,其中显示了正确格式化的注释。
我试图列出一个清单(从这里复制):
/// <summary>Here is an example of a bulleted list:
/// <list type="bullet">
/// <item>
/// <description>Item 1.</description>
/// </item>
/// <item>
/// <description>Item 2.</description>
/// </item>
/// </list>
/// </summary>
Run Code Online (Sandbox Code Playgroud)
但是弹出窗口只在一行中显示它:
Here is an example of a bulleted list: Item 1. Item 2.
Run Code Online (Sandbox Code Playgroud)
我也尝试添加<term>它(就像这里),但我得到的只是:
我也试过其他type的(也没有),但没有改变。这是一个错误吗?我如何解决它?
如果我有这样的位置记录:
public record Version(int Major, int Minor);
Run Code Online (Sandbox Code Playgroud)
看来我只能提供一个<summary>文档,像这样:
/// <summary>
/// Version record
/// </summary>
public record Version(int Major, int Minor);
Run Code Online (Sandbox Code Playgroud)
是否可以在保持简短记录语法的同时记录Major和Minor属性(也可能是构造函数参数)?
下面的注释只是VS中的一段xml注释,但我的问题是< >破坏xml结构的字符.如何在xml注释中使用它们?
/// <param name="index">square index on board which 1<=index<=64</param>
Run Code Online (Sandbox Code Playgroud) 我使用XmlDocument来解析xml文件,但似乎XmlDocument始终将xml注释作为xml节点读取:
我的C#代码
XmlDocument xml = new XmlDocument();
xml.Load(filename);
foreach (XmlNode node in xml.FirstChild.ChildNodes) {
}
Run Code Online (Sandbox Code Playgroud)
Xml文件
<project>
<!-- comments-->
<application name="app1">
<property name="ip" value="10.18.98.100"/>
</application>
</project>
Run Code Online (Sandbox Code Playgroud)
.NET不应该跳过XML注释吗?
可能重复:
在.NET中使用XML注释的优点是什么?
/// <summary>
/// Set error message for multilingual language.
/// </summary>
Run Code Online (Sandbox Code Playgroud)
在C#中使用如上所述的XML注释有什么用?我何时使用它们.XML注释带有3个引号,是否存在XML注释的块注释过程,如/*...*/
xml-comments ×10
c# ×9
xml ×3
.net ×1
c#-9.0 ×1
f# ×1
intellisense ×1
record ×1
xmldocument ×1
xsd ×1