Skip to content

Clarify interface implementation accessibility requirements and provide comprehensive guidance for internal interfaces #48050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 22, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 20, 2025

The documentation for interface implementation stated that implementing members "must be public" without clarifying this applies only to implicit implementation. Additionally, it incorrectly suggested that internal interfaces always require explicit implementation, when in fact they can use implicit implementation as long as all types in the signature are publicly accessible.

Changes Made

Updated the core statement on line 29 to clarify that the public requirement applies specifically to implicit implementation:

To implement an interface member using implicit implementation, the corresponding member of the implementing class must be public, non-static, and have the same name and signature as the interface member. However, when an interface has internal accessibility or uses internal types in its signature, you can use explicit interface implementation instead, which doesn't require the implementing member to be public.

Revised "Working with internal interfaces" section to accurately explain:

  • Internal interfaces can typically be implemented using implicit implementation with public members, as long as all types in the interface signature are publicly accessible
  • Explicit interface implementation is only required when internal types are used in member signatures
  • Added comprehensive example demonstrating both scenarios

Enhanced code example showing:

// Internal interface that CAN use implicit implementation
internal interface ILoggable
{
    void Log(string message); // string is public, so implicit implementation works
}

// Internal interface that REQUIRES explicit implementation  
internal interface IConfigurable
{
    void Configure(InternalConfiguration config); // Internal type prevents implicit implementation
}

public class ServiceImplementation : ILoggable, IConfigurable
{
    // Implicit implementation works for ILoggable
    public void Log(string message) { ... }
    
    // Explicit implementation required for IConfigurable
    void IConfigurable.Configure(InternalConfiguration config) { ... }
}

This provides accurate guidance on when each implementation approach is needed and addresses the confusion around internal interfaces and accessibility requirements.

Fixes #44194.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.


Internal previews

📄 File 🔗 Preview link
docs/csharp/fundamentals/types/interfaces.md Interfaces - define behavior for multiple types

…ity requirements

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] A bit more detail on that (or better, why) methods that implement interface methods have to be public even with the interface method is, say, internal. Clarify interface implementation accessibility requirements and add explicit implementation guidance Aug 20, 2025
Copilot finished work on behalf of BillWagner August 20, 2025 21:40
@Copilot Copilot AI requested a review from BillWagner August 20, 2025 21:40
@BillWagner BillWagner marked this pull request as ready for review August 21, 2025 13:45
@BillWagner BillWagner requested a review from a team as a code owner August 21, 2025 13:45
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start, but has misleading information.

@copilot address the review comments.

@BillWagner BillWagner marked this pull request as draft August 21, 2025 14:59
…pabilities and add comprehensive example

Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Aug 21, 2025

This is a good start, but has misleading information.

@copilot address the review comments.

I've addressed the review feedback about the misleading information. The documentation now correctly explains that internal interfaces can typically be implemented with public members when all signature types are publicly accessible. I've added a comprehensive example showing both scenarios: when implicit implementation works and when explicit implementation is required.

Changes in commit 563cf2e.

@Copilot Copilot AI changed the title Clarify interface implementation accessibility requirements and add explicit implementation guidance Clarify interface implementation accessibility requirements and provide comprehensive guidance for internal interfaces Aug 21, 2025
Copilot finished work on behalf of BillWagner August 21, 2025 15:06
@Copilot Copilot AI requested a review from BillWagner August 21, 2025 15:06
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good, once there's a small change.

@BillWagner BillWagner marked this pull request as ready for review August 21, 2025 18:18
@BillWagner BillWagner requested review from adegeo and a team August 21, 2025 18:18
@BillWagner BillWagner enabled auto-merge (squash) August 22, 2025 18:14
Copy link
Contributor

@adegeo adegeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@BillWagner BillWagner merged commit 27a54b7 into main Aug 22, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-44194 branch August 22, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

A bit more detail on that (or better, why) methods that implement interface methods have to be public even with the interface method is, say, internal.
3 participants