Skip to content
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

[docs] Add design doc about how we're improving our generator support in .NET 9. #16293

Closed
wants to merge 3 commits into from

Conversation

rolfbjarne
Copy link
Member

@rolfbjarne rolfbjarne commented Oct 7, 2022

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 #13294.

@rolfbjarne rolfbjarne added not-notes-worthy Ignore for release notes request-for-comments The issue is a suggested idea seeking feedback labels Oct 7, 2022
@rolfbjarne rolfbjarne added this to the .NET 8 milestone Oct 7, 2022
@rolfbjarne rolfbjarne added this to Default interface members in .NET 8 - Themes Oct 7, 2022
@rolfbjarne rolfbjarne self-assigned this Oct 7, 2022
@rolfbjarne rolfbjarne added the do-not-merge Do not merge this pull request label Oct 7, 2022
@rolfbjarne
Copy link
Member Author

Don't merge until we're branching for net8.0(and in that case re-target the PR to net8.0).

@chamons
Copy link
Contributor

chamons commented Oct 10, 2022

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 ();

@rolfbjarne
Copy link
Member Author

@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 ();
    }
}

@chamons
Copy link
Contributor

chamons commented Oct 10, 2022

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.

@rolfbjarne
Copy link
Member Author

@chamons yes, that should work

@rolfbjarne rolfbjarne removed this from Default interface members in .NET 8 - Themes Sep 5, 2023
@rolfbjarne rolfbjarne added this to Features in .NET 9 Sep 5, 2023
@rolfbjarne rolfbjarne modified the milestones: .NET 8, .NET 9 Nov 9, 2023
@dalexsoto dalexsoto changed the title [docs] Add design doc about how we're improving our generator support in .NET 8. [docs] Add design doc about how we're improving our generator support in .NET 9. Nov 10, 2023
@rolfbjarne rolfbjarne removed do-not-merge Do not merge this pull request not-notes-worthy Ignore for release notes labels Feb 20, 2024
@rolfbjarne
Copy link
Member Author

Superseded by #20681.

@rolfbjarne rolfbjarne closed this Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
request-for-comments The issue is a suggested idea seeking feedback
Projects
.NET 9
Features
Development

Successfully merging this pull request may close these issues.

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