我正在记录我在C#中编写的一些处理解析令牌的方法.由于系统其他领域的一些技术限制,这些令牌需要采用XML元素的形式(即<tokenName />
).我想将这些令牌的格式放在摘要语句中.
但是,这会引发错误:格式错误 - 名称以无效字符开头".是否有任何类型的转义字符序列可用于在我的C#摘要注释中嵌入XML?
And*_*ott 39
使用标准XML转义.例如:
<summary>This takes a <token1> and turns it into a <token2></summary>
Run Code Online (Sandbox Code Playgroud)
输入或读取代码并不是一件容易的事,但是IntelliSense正确地解决了这个问题,你在工具提示中看到了正确的,可读的东西.
Sea*_*ean 27
使用CDATA部分.例如:
<![CDATA[ <name>Bob</name> ]]>
Run Code Online (Sandbox Code Playgroud)
当您拥有更大的XML片段时,这在源代码中比在实体引用中编码特殊字符更优雅和可读.
如果要嵌入的XML本身包含CDATA部分,则需要使用多个CDATA部分,如Stack Overflow或Wikipedia 上的另一个答案中所述.或者您可以始终使用普通实体引用,如此处的其他答案中所述.
很晚了,但遇到了同样的问题,使用<![CDATA[]]>
将隐藏智能感知中的评论。
更换两个<
和>
是为我的许多工作(懒惰:))。我发现对于 Intellisense仅替换<
with<
就足够了,因为它使 xml 无效并且适合 Intellisense 将其解析为摘要块中的文本。
下面是一个例子:
/// <summary>
/// Parse the queue process response
/// <para><?xml version="1.0" encoding="utf-16"?><result success="True"><entity type="resource" operation="update" /></result></para>
/// <![CDATA[
/// <?xml version="1.0" encoding="utf-16"?><result success="True"><entity type="resource" operation="update" /></result>
/// ]]></summary>
/// <param name="response"></param>
/// <returns></returns>
Run Code Online (Sandbox Code Playgroud)
智能感知将显示:
Parse the queue process response
<?xml version="1.0" encoding="utf-16"?><result success="True"><entity type="resource" operation="update" /></result>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10771 次 |
最近记录: |