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() 
相關問題