使用C#内部访问修饰符进行Doxygen

我正在使用Doxygen为我正在开发的C#项目生成一些API文档。 我在这个项目中有相当多的“内部”function,并且不希望Doxygen在它生成的生成的html中产生这些签名。

我尝试过启用HIDE_FRIEND_COMPOUNDS,但这仍然导致我的内部类在生成的文档中公开。

有谁知道如何做到这一点?

添加到Mac H的答案,你必须设置这些额外的配置参数,使其工作:

# The PREDEFINED tag can be used to specify one or more macro names that # are defined before the preprocessor is started (similar to the -D option of # gcc). PREDEFINED = internal=private # If the EXTRACT_PRIVATE tag is set to YES all private members of a class # will be included in the documentation. EXTRACT_PRIVATE = NO # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will # evaluate all C-preprocessor directives found in the sources and include # files. ENABLE_PREPROCESSING = YES # If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro # names in the source code. If set to NO (the default) only conditional # compilation will be performed. Macro expansion can be done in a controlled # way by setting EXPAND_ONLY_PREDEF to YES. MACRO_EXPANSION = YES # If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES # then the macro expansion is limited to the macros specified with the # PREDEFINED and EXPAND_AS_DEFINED tags. EXPAND_ONLY_PREDEF = YES 

这是一个旧条目,但我遇到了同样的问题。

对我有用的方法是简单地使用doxygen的’predefine’function。 如果你预定义’internal = private’(相当于做’#define internal private’),那么Doxygen会将所有’内部’属性视为’私有’ – 所以如果请求则忽略它们。

这是一个kludge – 但它的工作原理。

doxygen有几种方法可以通过在配置文件中设置选项来从文档中排除代码。

如果您的方法是私有的,那么设置EXTRACT_PRIVATE = NO

您还可以指定排除模式,例如,如果您的私有类位于名为hidden的目录中,则可以通过设置排除该目录中的所有文件。

 EXCLUDE_PATTERNS = */hidden/* 

您也可以通过设置避免包含未记录的代码。

 HIDE_UNDOC_CLASSES = YES 

 HIDE_UNDOC_MEMBERS = NO 

刚刚遇到主题…使用\ internal doxygen关键字,它只是为此设计的。

设置

 HIDE_UNDOC_CLASSES = YES 

适用于我,即使默认值为EXTRACT_PRIVATEPREDEFINED 。 不确定原因。 我希望它们必须设置为NO (因此私有成员没有可用的文档)和internal=private (因此文档也从内部类中删除),但事实并非如此。 生成的文档中不再提及internalprivate类。

Doxygen显然认为C#类和结构的默认值是公共的,而不是内部的,并且会将它们记录下来。 但是, 如果您明确使用C# internal访问修饰符,Doxygen会尊重它 (在某种程度上)。 所以,在这个源上运行Doxygen:

 namespace Test_Library { ///  /// I should be documented. ///  public class ExplicitPublicClass { public int Field; } ///  /// I should NOT be documented. ///  class ImplicitInternalClass { public int Field; } ///  /// I should NOT be documented. ///  internal class ExplicitInternalClass { public int Field; } ///  /// I should be documented. ///  public struct ExplicitPublicStruct { public int Field; } ///  /// I should NOT be documented. ///  struct ImplicitInternalStruct { public int Field; } ///  /// I should NOT be documented. ///  internal struct ExplicitInternalStruct { public int Field; } } 

在Doxygen的输出中获取此类列表:

 C ExplicitPublicClass I should be documented. C ExplicitPublicStruct I should be documented. C ImplicitInternalClass I should NOT be documented. C ImplicitInternalStruct I should NOT be documented. 

但是,您仍然可以在“命名空间参考:”下的Doxygen的类列表中获取显式内部类和结构。

 class ExplicitInternalClass I should NOT be documented. struct ExplicitInternalStruct I should NOT be documented. class ExplicitPublicClass I should be documented. More... struct ExplicitPublicStruct I should be documented. More... class ImplicitInternalClass I should NOT be documented. More... struct ImplicitInternalStruct I should NOT be documented. More... 

但请注意,实际文档的“更多…”链接(以及相关类/结构名称中可用的链接)不适用于前两个。

因此,您可以使用C#的显式internal访问修饰符来获取您正在寻找的一些行为,但不一定是您正在寻找的所有行为。 (作为比较,VSDocMan完全按照您希望的方式处理上面的源代码:只记录显式公共类和结构,没有提及显式或隐式内部类或结构。)