开发者

Doxygen with C# internal access modifier

开发者 https://www.devze.com 2022-12-13 22:07 出处:网络
I am using Doxygen to generate some API docs for a C# project I am working on. I have quite a bit of \"internal\" functionality in this project and don\'t want Doxygen producing these signatu开发者_St

I am using Doxygen to generate some API docs for a C# project I am working on. I have quite a bit of "internal" functionality in this project and don't want Doxygen producing these signatu开发者_StackOverflow社区res in the generated html it produces.

I have tried enabling HIDE_FRIEND_COMPOUNDS but this still results in my internal classes being exposed in the generated documentation.

Does anyone know how to do this?


Addon to Mac H's answer, you have to set these additional configuration parameters to make it work:

# 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


This is an old entry, but I had the same issue.

A method that works for me is to simply use the 'predefine' feature of doxygen. If you predefine 'internal=private' (which is equivalent to doing a '#define internal private') then Doxygen will see all 'internal' properties as 'private' - and so ignore them if requested.

It's a kludge -but it works.


doxygen has several methods to exclude code from the documentation by way of setting options in the configuration file.

If your methods are private then set EXTRACT_PRIVATE = NO

You can also specify to exclude patterns, for example, if your private classes are located in a directory called hidden, you can exclude all files in that directory by setting.

EXCLUDE_PATTERNS = */hidden/* 

Also you can avoid including non documented code by setting.

HIDE_UNDOC_CLASSES = YES

and

HIDE_UNDOC_MEMBERS = NO


Just came across the topic... use \internal doxygen keyword, it is designed just for that.


Setting

HIDE_UNDOC_CLASSES = YES

works for me, even with EXTRACT_PRIVATE and PREDEFINED on default values. Not sure about the reason. I would expect they are required to be set on NO (so there is no documentation available for private members) and internal=private (so documentation is removed from internal classes as well), but that is not the case. internal and private classes are not mentioned anymore anywhere in the generated documentation.


Doxygen apparently thinks the default for C# classes and structs is public, not internal, and will document them as such. However, if you explicitly use the C# internal access modifier, Doxygen respects it (to a degree). So, running Doxygen on this source:

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;
    }
}

gets you this Class List in Doxygen's output:

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. 

However, you do still get the explicitly internal classes and structs in Doxygen's list of classes under "Namespace Reference:"

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...

But note that the "More..." link to the actual documentation (as well as the link available in the associated class/struct name) is not available for the first two.

So, you can get some of the behavior you are looking for by using C#'s explicit internal access modifier, but not necessarily all of the behavior you are looking for. (By way of comparison, VSDocMan processes the source code above exactly the way you want it to: only the explicitly public class and struct are documented, with no mention of either the explicitly, nor implicitly, internal classes or structs.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号