Doxygen with C# internal access modifier

前端 未结 6 1639
故里飘歌
故里飘歌 2021-02-19 10:27

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

相关标签:
6条回答
  • 2021-02-19 10:54

    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
    
    0 讨论(0)
  • 2021-02-19 11:04

    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.

    0 讨论(0)
  • 2021-02-19 11:07

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

    0 讨论(0)
  • 2021-02-19 11:13

    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.

    0 讨论(0)
  • 2021-02-19 11:20

    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
    
    0 讨论(0)
  • 2021-02-19 11:20

    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 讨论(0)
提交回复
热议问题