ClangSharp icon indicating copy to clipboard operation
ClangSharp copied to clipboard

Make marker interfaces partial to support user extensions

Open tompipe opened this issue 1 month ago • 4 comments

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 avatar Oct 30 '25 18:10 tompipe

@dotnet-policy-service agree

tompipe avatar Nov 01 '25 12:11 tompipe

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.

tannergooding avatar Nov 01 '25 14:11 tannergooding

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.

tompipe avatar Nov 01 '25 17:11 tompipe

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?

tannergooding avatar Nov 01 '25 17:11 tannergooding