Visual Studio 2017文档注释中<符号导致显示异常的解决办法
解决Visual Studio 2017文档注释中<符号显示异常的问题
问题根源在于Visual Studio的文档注释基于XML语法,<会被XML解析器识别为标签起始符,直接在<code>块中使用会导致解析错误,进而让文档无法正常显示。
解决方法有两种:
方法一:使用XML转义字符
将代码中的<替换为XML转义字符<,XML解析器会将其视为普通文本处理。修改后的注释代码如下:
/// <summary> /// Procedure that returns a list of people with the given first and last name. /// /// <para> /// name and surname are not case sensitive. (Friedrich Schiller == FrIedRich SCHIller) /// /// <code> /// IList<Person> personList = _personService.GetList("friedrich","schiller"); /// </code> /// </para> /// </summary>
方法二:使用CDATA块
将<code>内的代码包裹在<![CDATA[ ... ]]>中,CDATA块内的内容会被XML解析器当作纯文本,不会解析特殊字符。修改后的注释代码如下:
/// <summary> /// Procedure that returns a list of people with the given first and last name. /// /// <para> /// name and surname are not case sensitive. (Friedrich Schiller == FrIedRich SCHIller) /// /// <code> /// <![CDATA[ /// IList<Person> personList = _personService.GetList("friedrich","schiller"); /// ]]> /// </code> /// </para> /// </summary>
两种方法都能解决问题,CDATA块更适合包含多个特殊字符的代码片段,转义字符则适合单个特殊字符的场景,可根据实际情况选择。
内容的提问来源于stack exchange,提问作者tahasozgen
相关产品推荐
相关产品推荐

