-
Notifications
You must be signed in to change notification settings - Fork 4.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
Proposal: Allow implicit implementation of internal interfaces #3599
Comments
Here's another usage: internal-only setters for properties
That should be valid because the get has greater visibility than the interface requires. |
📝 You are only forced to implement the interface explicitly when the signature includes internal types. Otherwise you do have the option of creating a 💭 I think this proposal would be more clearly worded as follows (and I would likely be in support of this):
|
@sharwell in my example, I got errors unless I used an explicit impl. The types were not internal. |
@onovotny The problem is your internal interface IMyInterface
{
void MyMethod();
}
public class MyClassImplicit : IMyInterface
{
public void MyMethod() { }
} ¹ I could be wrong here; I have not verified whether this restriction applies to interfaces which are nested within another type. |
@sharwell In my example, I have an property with different accessibility for the setter. The idea is that for consumers of my library, I want the object to be unchangeable. Inside my library, I want to pass the object around as an interface as I'm doing things via interface composition. So I have an internal interface that has the get/set. I'd expect, and hence the proposal here, that a public get/internal set would be able to implement the interface. |
@onovotny That's exactly what I said with my summarized version of your proposal. 😄 |
Good point on the internal member types (that's actually my real scenario). |
We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages. See also #18002 for a general discussion of closing and/or moving language issues out of this repo. |
@gafter So we need to move these over? Or are you closing it because you did? |
I closed it because it hasn't been commented in over a year, the LDM isn't tracking it, and there is nobody on the LDM who has taken it up as a champion. Yes, if you're still interested in this, please move it over. See also #18002 for a general discussion of closing and/or moving language issues out of this repo. |
Let me get this straight: If you ignore the issue long enough and no one with the power to make things happen bother making a proper informed decision, it gets closed? So we should add a useless "ping" comment every few months to "keep it alive" ? Just because it hasn't been picked up for implementation, doesn't mean it's invalid or a bad idea. |
No, a ping will just move it later on the list of issues to be dealt with. See #18002 for a general discussion of closing and/or moving language issues out of this repo. This discussion is off topic here. |
To add to that, the reason I closed this issue is that, besides the lack of community interest, my informed opinion is that this would never rise to the level needed for us to devote any effort to making it happen, and even if someone on the language design team tried to push it, there would be pushback. However, you're welcome to open an issue on csharplang and continue discussion of the proposal. If there were enough community support it is possible (though unlikely in my opinion) that we would devote resources to this instead of the scores of (in my opinion) more valuable proposals under consideration. |
@gafter see you should just have said that in the first place :-). Getting your issues closed just because they have gone stale in the Roslyn team's queue, is very discouraging to the community. |
When you want to implement an interface on a class, you can do it implicit or explicit. Ie
However if I create an internal interface You are forced to implement interfaces explicitly.
Implementing implicitly has a lot of nice features - I don't have to always cast to the interface to use it. This becomes very useful for wrapping native interop classes. I can create an interface that ensures that all classes that wrap native objects follow a common pattern. For instance:
That way if all my classes that wrap my features from my native interop layer all expose the pointer (or similar) in a common way, and always implements IDisposable. So I can just write
However, because I'm forced to explicitly implement classes, this benefit goes away somewhat, by forcing casting on my, and it's not as discoverable from intellisense code that this is available.
Naturally if you implement an internal interface implicitly, you would be forced to use the 'internal' or a more accessible modifier on the members.
The text was updated successfully, but these errors were encountered: