如何在Visual Studio 2017的XML文档注释中实现换行?
在Visual Studio 2017的XML文档注释中添加换行的解决方案
在VS的XML文档注释里,纯文本的\n不会被解析为换行,要实现排版换行,需使用XML原生标签控制:
方法1:用<br/>标签强制换行
在需要拆分内容的位置直接插入<br/>,适合同一段内的换行需求:
public interface IPersonService : IDisposable { /// <summary> /// Procedure that returns a list of people with the given first and last name. /// /// <para> /// First and last names are not case sensitive. ('friedrich schiller' == 'fRieDrich scHIller') /// </para> /// <example> /// The following example returns a list of people with the first name 'friedrich' and the last name 'schiller':<br/> /// <code> /// IList <Person> personList = _personService.GetList("friedrich","schiller"); /// </code> /// </example> /// </summary> /// <param name="name">Name of the person being called. It cannot be null. It is not case sensitive.</param> /// <param name="surname">Surname of the person being called. It cannot be null. It is not case sensitive.</param> /// <returns> /// IList<Person>: List of people with name and surname,<br/> /// Empty list: If there is no person matching the given name and surname. /// </returns> IList<Person> GetList(string name, string surname); }
方法2:用<para>标签创建段落换行
如果需要将内容拆分为独立段落,用<para>包裹对应内容,VS会自动在段落间添加合理的换行和间距,排版更规整:
public interface IPersonService : IDisposable { /// <summary> /// Procedure that returns a list of people with the given first and last name. /// /// <para> /// First and last names are not case sensitive. ('friedrich schiller' == 'fRieDrich scHIller') /// </para> /// <example> /// <para>The following example returns a list of people with the first name 'friedrich' and the last name 'schiller':</para> /// <code> /// IList <Person> personList = _personService.GetList("friedrich","schiller"); /// </code> /// </example> /// </summary> /// <param name="name">Name of the person being called. It cannot be null. It is not case sensitive.</param> /// <param name="surname">Surname of the person being called. It cannot be null. It is not case sensitive.</param> /// <returns> /// <para>IList<Person>: List of people matching the given name and surname.</para> /// <para>Empty list: Returned when no matching people are found.</para> /// </returns> IList<Person> GetList(string name, string surname); }
原理说明
XML文档注释遵循XML语法规则,VS的注释解析器只会识别XML标签处理排版,普通文本中的换行符(\n)会被忽略。<br/>用于强制换行,<para>用于创建独立段落,两种方式都能在VS智能提示、生成的文档中正确渲染出换行效果。
内容的提问来源于stack exchange,提问作者tahasozgen
相关产品推荐
相关产品推荐

