[docs] Add design doc about how we're improving our generator support in .NET 9.
This is a proposal for how to improve our generator support for protocols using C#'s default interface member and static interface member features.
Comments, ideas, etc. are welcome!
For an initial review it might be easier to read the rendered document: https://github.com/rolfbjarne/xamarin-macios/blob/net8.0-dim/docs/objective-c-protocols.md
Fixes https://github.com/xamarin/xamarin-macios/issues/13294. Fixes https://github.com/xamarin/xamarin-macios/issues/14039.
Don't merge until we're branching for net8.0(and in that case re-target the PR to net8.0).
I think the "Coping with C# quirks" section covers the nonsense I ran into, and "inlining" versions that cast to base is the best solution.
I'm wondering however, would that work if you are a customer and have a derived class?
// class MyWindow : UIWindow
MyWindow * w = new MyWindow ();
w.SomethingOnAndInterface ();
@chamons I'm not quite sure I understand your example.
If your custom class implements the interface, then no, it wouldn't work:
public interface IProtocol {
public void DoSomething () {}
}
public class MyWindow : UIWindow, IProtocol {
public void Hello ()
{
this.DoSomething (); // this doesn't work
((IProtocol) this).DoSomething (); // this works
}
}
public class MyWindow2 : UIWindow, IProtocol {
public void Hello ()
{
this.DoSomething (); // this works now, it calls the method below
}
public void DoSomething ()
{
((IProtocol) this).DoSomething ();
}
}
I was wondering out loud about this:
Our Binding
public interface IProtocol {
public void DoSomething () {}
}
public class UIWindow: IProtocol {
public void DoSomething () {
((IProtocol) this).DoSomething ();
}
}
User Code
public class MyWindow : UIWindow {
// Unrelated changed
}
public void Foo (MyWindow window)
{
window.DoSomething()
}
And I think that'd work.
@chamons yes, that should work
Superseded by https://github.com/xamarin/xamarin-macios/pull/20681.