Skip to content

Conversation

@tompipe
Copy link

@tompipe tompipe commented Oct 30, 2025

Summary

Makes generated marker interfaces partial to allow users to manually extend them with custom implementations.

Fixes #647

Changes

  • Modified CSharpOutputBuilder.VisitDecl.cs:829 to generate public partial interface Interface instead of public interface Interface

Why

When --generate-marker-interfaces is enabled, users may want to manually add custom helper methods to the interface contract. Without the partial keyword, this is impossible.

Impact

  • Non-breaking: Adding partial to an interface is backward compatible
  • Consistent: Matches the existing pattern where generated structs are already partial
  • Enables: User extensions for excluded methods, custom helpers, or manual implementations of unsupported C++ constructs

Testing

  • Built successfully with dotnet build
  • No compilation errors or warnings

🤖 Generated with Claude Code

Co-Authored-By: Claude [email protected]

tompipe and others added 2 commits October 30, 2025 18:15
When --generate-marker-interfaces is enabled, generated nested interfaces
are now marked as 'partial' to allow users to extend them with manual
method implementations. This is critical when:

- Methods are excluded via --exclude or other exclusion flags
- Template methods or other unsupported constructs need manual implementation
- Helper methods should be part of the interface contract for generic constraints

Changed: public interface Interface -> public partial interface Interface

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@tompipe
Copy link
Author

tompipe commented Nov 1, 2025

@dotnet-policy-service agree

@tannergooding
Copy link
Member

When --generate-marker-interfaces is enabled, users may want to manually add custom helper methods to the interface contract. Without the partial keyword, this is impossible.

This is potentially problematic as it can break the ABI compatibility if users try to use these types with COM wrappers or similar functionality.

@tompipe
Copy link
Author

tompipe commented Nov 1, 2025

When --generate-marker-interfaces is enabled, users may want to manually add custom helper methods to the interface contract. Without the partial keyword, this is impossible.

This is potentially problematic as it can break the ABI compatibility if users try to use these types with COM wrappers or similar functionality.

True. But the primary use is to map methods that don't map correctly, at present that's possible for the main struct/class, but not the interface.

@tannergooding
Copy link
Member

But the primary use is to map methods that don't map correctly

The bindings should all be correct, if they aren't there is a bug in ClangSharp that needs fixing (particularly since that means you'd have a "bad definition" persisting in the interface).

Do you have an example of something that doesn't bind correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Marker interfaces should be partial to support user extensions

2 participants