xamarin-macios/docs
Rolf Bjarne Kvinge e9d59d5f58
[bgen] Implement support for using default interface members to bind protocols. (#20681)
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.

This PR also:

* Adds numerous tests.
* Updates the requiredness of a few members in Metal to test that it works as
  expected.
* Adds documentation.
* Handles numerous corner cases, which are documented in code and docs.

This PR is probably best reviewed commit-by-commit.

Fixes https://github.com/xamarin/xamarin-macios/issues/13294.
2024-06-07 16:35:48 +02:00
..
api [src/docs] Add xml documentation for types. (#20672) 2024-06-06 07:37:52 +02:00
website [docs] Review and update the 'Binding errors' document. (#20481) 2024-04-24 09:41:10 +02:00
CORECLR.md [configure] Add option to use a locally built dotnet/runtime. (#11643) 2021-05-21 22:18:25 +02:00
apple-privacy-manifest.md Apple Privacy Manifest doc updates (#20391) 2024-04-02 13:33:37 -04:00
bindas.md [docs] Document how to add support for new BindAs types. 2017-09-25 16:38:21 +02:00
bug-repro.md [fabricbot] Handle the 'need-repro' label. (#17272) 2023-01-18 18:33:48 +01:00
code-sharing-with-user-frameworks.md [docs] Clearify wording a bit about code sharing occuring once per architecture. 2017-02-20 17:14:14 +01:00
configuration-properties.md [docs] Document properties for configurations (#17940) 2023-03-30 12:22:32 -07:00
managed-static-registrar.md [docs] Improve a few things in the managed static registrar doc. (#19368) 2023-10-29 13:09:03 -04:00
multi-target-framework.md [dotnet] Multi target with Xcode 15.0 (#20155) 2024-02-28 09:03:53 +01:00
nativeaot.md [docs] Document NativeAOT support. Fixes #18585. (#19362) 2023-11-09 16:05:54 +01:00
objective-c-protocols.md [bgen] Implement support for using default interface members to bind protocols. (#20681) 2024-06-07 16:35:48 +02:00
preparing-your-app-for-testflight.md [docs]Created a doc for preparing an app for TestFlight (#18125) 2023-05-30 17:46:10 -04:00
preview-apis.md [CryptoTokenKit] Bind this framework. Fixes #7876. (#20587) 2024-05-29 20:38:40 +02:00
required-reasons-bcl.md Add documentation on how to provide the Apple Privacy Manifest (#20292) 2024-03-21 07:04:27 -04:00
required-reasons-dotnet-maui.md Add documentation on how to provide the Apple Privacy Manifest (#20292) 2024-03-21 07:04:27 -04:00
required-reasons-macios.md Add documentation on how to provide the Apple Privacy Manifest (#20292) 2024-03-21 07:04:27 -04:00