Skip to content

SA1600 triggers for private interface members #3551

Closed

Description

@gtbuchanan

Interfaces may have private members:

Interface members are public by default, and you can explicitly specify accessibility modifiers, such as public, protected, internal, private, protected internal, or private protected. A private member must have a default implementation.

SA1600 requires documentation of these members when documentPrivateElements: false. For example, PrivateMethod here is triggering SA1600:

/// <summary>
/// An interface with private members.
/// </summary>
public interface IInterfaceWithPrivateMembers
{
    private void PrivateMethod()
    {
    }

    /// <summary>
    /// A public method.
    /// </summary>
    public void PublicMethod() => this.PrivateMethod();
}

It makes sense for documentInterfaces: true to ignore documentInternalMembers since that appears to be its goal. However, I think private interface members should still consider documentPrivateElements in this case since the members are not accessible outside of the interface.

Tested with 1.2.0-beta.435.

Activity

  1. bjornhellander commented on Aug 20, 2022

    @bjornhellander
    Contributor

    See the description of documentInterfaces in https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/Configuration.md?plain=1#L577:
    Specifies whether interface members need to be documented. When true, all interface members require documentation, regardless of accessibility.
    Seems to be why this is happening.

  2. bjornhellander commented on Aug 20, 2022

    @bjornhellander
    Contributor

    Personally, I think the behaviour for internal members with bodies is correct, since implementors of the interface still needs to understand what the method is supposed to do to be able to override it when necesssary.

    Private methods with bodies is a different matter, since they can not be overridden or used by anyone else. I would find it reasonable if documentInterfaces did not apply to private members.

  3. gtbuchanan commented on Aug 30, 2022

    @gtbuchanan
    Author

    @bjornhellander What you're saying about internal interface members definitely makes sense in regards to documentInterfaces. I will update the title/description to only mention private members. I agree that private members should probably be treated as a special case.

  4. changed the title [-]SA1600 triggers for private/internal interface members[/-] [+]SA1600 triggers for private interface members[/+] on Aug 30, 2022
  5. bjornhellander commented on Jan 22, 2023

    @bjornhellander
    Contributor

    Any thoughts on @gtbuchanan's suggestion, @sharwell?

  6. added a commit that references this issue on Nov 26, 2025
    2959cac
  7. moved this from Backlog to In progress in StyleCopAnalyzerson Nov 26, 2025
  8. moved this from In progress to Done in StyleCopAnalyzerson Nov 30, 2025
  9. added this to the 1.2-beta.next milestone on Nov 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions