-
Notifications
You must be signed in to change notification settings - Fork 522
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
[bgen] Implement support for using default interface members to bind protocols. #20681
Conversation
…tion by fixing location.
…protocols. Given the following API definition: ```cs [Protocol] public interface Protocol { [Abstract] [Export ("requiredMethod")] void RequiredMethod (); [Export ("optionalMethod")] void OptionalMethod (); } ``` we're now binding it like this: ```cs [Protocol ("Protocol")] public interface IProtocol : INativeObject { [RequiredMember] [Export ("requiredMethod")] public void RequiredMethod () { /* default implementation */ } [OptionalMember] [Export ("optionalMethod")] public void OptionalMethod () { /* default implementation */ } } ``` The main difference from before is that the only difference between required and optional members is the [RequiredMember]/[OptionalMember] attributes. This has one major advantage: it's now possible to switch a member from being required to being optional, or vice versa, without breaking neither source nor binary compatibility. It also improves intellisense for optional members. In the past optional members were implemented using extension methods, which were not very discoverable when you were supposed to implement a protocol in your own class. The main downside is that the C# compiler won't enforce developers to implement required protocol members (which is a necessary side effect of the fact that we want to be able to switch members between being required and optional without breaking compatibility). If this turns out to be a problem, we can implement a custom source analyzer and/or linker step that detects missing implementations and issue warnings/errors. Also: * Add numerous tests. * Add documentation. * Handle numerous corner cases, which are documented in code and docs. Fixes dotnet#13294.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 and I think that we should invest more on roslyn analyser over complicated attributes, is a better approach and will be more helpful for our clients.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
📚 [PR Build] Artifacts 📚Packages generatedView packagesPipeline on Agent |
✅ API diff for current PR / commitLegacy Xamarin (No breaking changes).NET (No breaking changes)✅ API diff vs stableLegacy Xamarin (No breaking changes).NET (No breaking changes)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
Given the following API definition:
we're now binding it like this:
The main difference from before is that the only difference between required
and optional members is the [RequiredMember]/[OptionalMember] attributes.
This has one major advantage: it's now possible to switch a member from being
required to being optional, or vice versa, without breaking neither source nor
binary compatibility.
It also improves intellisense for optional members. In the past optional
members were implemented using extension methods, which were not very
discoverable when you were supposed to implement a protocol in your own class.
The main downside is that the C# compiler won't enforce developers to
implement required protocol members (which is a necessary side effect of the
fact that we want to be able to switch members between being required and
optional without breaking compatibility). If this turns out to be a problem,
we can implement a custom source analyzer and/or linker step that detects
missing implementations and issue warnings/errors.
This PR also:
expected.
This PR is probably best reviewed commit-by-commit.
Fixes #13294.