-
Notifications
You must be signed in to change notification settings - Fork 1k
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
!Lightweight! Default interface members implementation. Primary for backward compatibility of improved BCL interfaces. MINIMAL CLR CHANGES ARE REQUIRED. #222
Comments
An existing, championed, proposal already exists for this: Champion "default interface methods" |
Cool! |
As I dislike the idea of language features promoting the use of inheritance, much less multiple inheritance, I downvoted that championed proposal. Downvoting this one too, for consistency (nothing personal!). |
Please let split this "Champion" into two proposals.
This proposal does not requires any CLR changes, only C# compiler improvement. public interface IMyContract
{
// No any property/method/statics supported here.
// Saving CLR from changes.
// This will be injected as explicit implementation by Compiler. CLR will not do anything new.
public int GetAnswerForEverything()
{
return GreatThinker.GiveMeAnwerToEverything();
}
}
public static class GreatThinker
{
// 42 returner.
public int GiveMeAnswerToEverything()
{
// Artificial intelligence inside.
}
} But this #52 proposal turns interfaces to C++ interfaces and bring multiple inheritance hell to C# |
This proposal doesn't solve the main point of the championed proposal, that is to allow an interface in a separate assembly to add a "default" member without breaking any other compiled assemblies containing classes that implement that interface. |
The championed proposal renders this proposal entirely obsolete. The implementation is nearly identical, except that the CLR is responsible for wiring up the static default instead of the compiler. I don't see room for both proposals. And considering that the other proposal is actually already "championed" by a member of the C# design team, I can't imagine that they would consider an alternative that solves fewer problems. |
This proposal doesn't solve that problem. If the BCL were to add new members to existing interfaces all assemblies containing classes implementing those interfaces would fail until they are recompiled. That requirement makes it largely useless. |
Yes, unfortunately you are right CLR changes are required even for this proposal. |
We can close this proposal. It's just implementation stage of #52 |
THIS IS LIGHTWEIGHT SUBSET OF #52
That can be implemented sooner than #52
Interfaces can also define standard implementation based on base contracts elements.
This feature will:
For example with this feature we can easily add IsReadOnly property to IReadOnlyCollection:
(see proposal https://github.com/dotnet/corefx/issues/16660)
(https://github.com/dotnet/corefx/issues/16626)
The text was updated successfully, but these errors were encountered: