xamarin-macios icon indicating copy to clipboard operation
xamarin-macios copied to clipboard

.NET: create a spec for how to add support for default interface members

Open rolfbjarne opened this issue 4 years ago • 2 comments

We've had support for default interface methods for a while, and the plan is to use them to improve our support for Objective-C protocols.

However, we haven't spec'ed out exactly how we're going to do that.

We should do this before .NET 6, because we can make breaking changes now: #13087 - this doesn't mean that adding support for default interface methods will include breaking changes, but before that train leaves we should spec it out to determine if we might want to do breaking changes (and implement them).

One major goal we should strive for would be for a method or property to go back and forth between being optional and required, and it shouldn't be a breaking API change either way.

This probably means that the optional/required state of a protocol member should be stored in an attribute on the method/property.


Need to look into https://github.com/xamarin/xamarin-macios/issues/20265 as well as part of this work.

rolfbjarne avatar Nov 05 '21 16:11 rolfbjarne

If we go down this route, this is an old (multiple years) branch with some work I did originally before we decided DIM wasn't helpful - https://github.com/chamons/xamarin-macios/commits/default_impl_prototype

chamons avatar Jan 25 '22 16:01 chamons

This turned out a bit annoying to implement, because there's no way to call the default implementation from an implementing class.

This feature was cut from C# 8, supposedly to return in C# 9, but that never happened.

  • https://github.com/dotnet/roslyn/issues/32054
  • https://github.com/dotnet/csharplang/issues/2337
  • https://github.com/dotnet/csharplang/issues/2910

rolfbjarne avatar Mar 06 '24 11:03 rolfbjarne