Skip to content

C# 11: Support for explicit interface implementations of operators. #12322

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

Merged

Conversation

michaelnebel
Copy link
Contributor

@michaelnebel michaelnebel commented Feb 27, 2023

In this PR we implement proper support (to align with the implementation for methods) for explicit implementation of interface operator members.
Prior to this PR the implementation of + in the example below was not identified as being neither public nor an implementation of + from the INumber<T> interface.

public interface INumber<T> where T : INumber<T>
{
    static abstract T operator +(T left, T right);
}

public class Complex : INumber<Complex>
{
    static Complex INumber<Complex>.operator +(Complex left, Complex right) =>
        new Complex { Real = left.Real + right.Real, Imaginary = left.Imaginary + right.Imaginary };
}

@michaelnebel michaelnebel marked this pull request as ready for review February 27, 2023 15:38
@michaelnebel michaelnebel requested a review from a team as a code owner February 27, 2023 15:38
@michaelnebel michaelnebel force-pushed the csharp/operatorexplicitinterface branch from fd2a903 to cb2e31d Compare February 28, 2023 14:40
@michaelnebel
Copy link
Contributor Author

DCA looks good.

hvitved
hvitved previously approved these changes Mar 1, 2023
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@michaelnebel michaelnebel merged commit 2db588f into github:main Mar 1, 2023
@michaelnebel michaelnebel deleted the csharp/operatorexplicitinterface branch March 1, 2023 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants