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

13

我正在使用Doxygen为我正在开发的一个C#项目生成一些API文档。在这个项目中,我有相当多的"内部"功能,不希望Doxygen在生成的html中显示这些签名。

我已经尝试启用了HIDE_FRIEND_COMPOUNDS选项,但是这仍然导致我的内部类在生成的文档中被公开。

是否有人知道如何解决这个问题?

6个回答

10

在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

1
关于编程:显然,除非您设置EXTRACT_STATIC = YES,否则Doxygen不会为“public static”类生成页面。显然,Doxygen认为在C#中,“static”的意义与它在C中的意义相同(即文件私有),这很愚蠢,因为即使在C ++中,“static”通常也不意味着那样。由于某种原因,如果没有此选项,此类仍将在类列表中列出(带有摘要),但是没有链接(不生成类页面)自v1.8.7起。(附言:哇,这些漏洞至少有4年了?!) - Qwertie

5

这是一个旧记录,但我遇到了相同的问题。

对我有效的一种方法是简单地使用Doxygen的“预定义”功能。如果您预定义了“internal=private”(相当于执行“#define internal private”),则Doxygen将把所有“internal”属性视为“private”,因此在请求时忽略它们。

这是一种权宜之计,但它能行。


1

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

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

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

EXCLUDE_PATTERNS = */hidden/* 

同时,您可以通过设置来避免包含未记录的代码。

HIDE_UNDOC_CLASSES = YES

HIDE_UNDOC_MEMBERS = NO

这些是C#内部类,不同于私有类。它们具有程序集范围:只有在同一程序集中的其他代码才能看到它们。我不希望这些类在文档中可见,我只想让公共类可见。 - Mike Gates

1

刚刚遇到这个话题... 使用\internal Doxygen关键字,它专门为此设计。


0

Doxygen 显然认为 C# 类和结构的默认访问修饰符是 public,而不是 internal,并将其作为 public 记录。然而,如果你明确使用 C# 的 internal 访问修饰符,Doxygen 将予以尊重(在一定程度上)。因此,在此源代码上运行 Doxygen:

namespace Test_Library
{
    /// <summary>
    /// I should be documented.
    /// </summary>
    public class ExplicitPublicClass
    {
        public int Field;
    }

    /// <summary>
    /// I should NOT be documented.
    /// </summary>
    class ImplicitInternalClass
    {
        public int Field;
    }

    /// <summary>
    /// I should NOT be documented.
    /// </summary>
    internal class ExplicitInternalClass
    {
        public int Field;
    }

    /// <summary>
    /// I should be documented.
    /// </summary>
    public struct ExplicitPublicStruct
    {
        public int Field;
    }

    /// <summary>
    /// I should NOT be documented.
    /// </summary>
    struct ImplicitInternalStruct
    {
        public int Field;
    }

    /// <summary>
    /// I should NOT be documented.
    /// </summary>
    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完全按照您想要的方式处理上面的源代码:仅记录明确公共类和结构,而没有提及明确或隐含的内部类或结构。)


0

设置

HIDE_UNDOC_CLASSES = YES

对我来说可以正常工作,即使在默认值上使用EXTRACT_PRIVATEPREDEFINED。不确定原因。我希望它们需要设置为NO(因此私有成员没有可用的文档),以及internal=private(因此文档也从内部类中删除),但事实并非如此。生成的文档中不再提到internalprivate类。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接