2

使用csc.exe编译源代码时,可以使用/doc选项将源文件中的xml文档注释保存到外部xml文件。为什么C#编译器在XML文档中包含非公共成员?

我想知道的是为什么编译器在该文件中包含我的代码的非公共成员的xml注释。由于我已经有源代码中的文档,因此在处理该项目时不需要xml文档文件中的任何内容。

如果我将dll用于另一个项目,我无法使用非公共成员。那为什么它包含所有私人和内部成员的文档?

我也想知道是否有办法阻止这种情况。

+0

我现在看到将所有内容放入XML文件的缺点。国际海事组织是这个工具的责任,可以从你的XML文件中创建可读的文档以适当地过滤。 – CodesInChaos 2013-02-09 10:03:27

+0

@CodesInChaos:你有一点,是的。虽然我仍然认为应该有一个选项来为公众成员生成文档。 (我正在研究一个API dll,我不希望我提供的XML文档文件包含有关我的库的内部信息,我希望不需要eazfuscator的文档过滤器,但看起来像我) – 2013-02-09 10:10:37

+0

相关信息[只为公众会员提取xml注释](http://stackoverflow.com/questions/624466/extract-xml-comments-for-public-members-only) – CodesInChaos 2013-02-09 10:25:25

回答

6

我可以理解记录的内部成员 - 这种方式可能会更容易浏览您在相同程序集中编写的代码的文档。 (当然,总是有InternalsVisibleTo)。对于私人成员,我认为这有点难以证明。

如果您使用Sandcastle生成脱机文档,您可以要求它仅生成一个仅包含公共成员的新XML文件,并且仅生成摘要部分。我不记得随便什么样子的SHFB,但在我们的野田时间的项目文件,我相信这是相关部分:

<ComponentConfig id="IntelliSense Component" enabled="True"> 
    <component id="IntelliSense Component" 
       type="SandcastleBuilder.Components.IntelliSenseComponent" 
       assembly="{@SHFBFolder}SandcastleBuilder.Components.dll"> 
     <output includeNamespaces="false" namespacesFile="Namespaces" 
       folder="{@OutputFolder}\..\PublicApi" /> 
    </component> 
    </ComponentConfig> 
1

这里是我的VBScript来过滤XML文档。

将strInputFile,strOutputFile更改为您的输入和输出XML文档文件。另外,更改“arrWhiteList = Array ...”一行,列出您希望获得文档的所有类型。

option explicit 

const strInputFile = "C:\Temp\YourModule.XML" 
const strOutputFile = "C:\Temp\YourModule.filtered.XML" 

Dim arrWhiteList 
arrWhiteList = Array("MyNamespace.Type1", "MyNamespace.Type2", "MyNamespace.Type3") 

Function isNameOk(strName) 
    Dim className, i 

    for each className in arrWhiteList 
     i = InStr(strName, className) 
     if i = 3 Then 
      isNameOk = True 
      exit function 
     end if 
    Next 
    isNameOk = false 
end function 

Sub Main() 
    Dim objXml, dicToRemove 
    Set objXml = CreateObject("Msxml2.DOMDocument.6.0") 
    objXml.Load strInputFile 

    Set dicToRemove = CreateObject("Scripting.Dictionary") 

    Dim node, strName 
    for each node in objXml.documentElement.SelectNodes("//member") 
     strName = node.getAttribute("name") 
     if not isNameOk(strName) then 
      dicToRemove.add node, "" 
     end if 
    Next 

    Dim nodeMembers, arrKeys 
    Set nodeMembers = objXml.documentElement.SelectSingleNode("//members") 
    arrKeys = dicToRemove.Keys 

    for each node in arrKeys 
     nodeMembers.removeChild node 
    next 

    objXml.save strOutputFile 
End Sub 

Call Main() 
相关问题