Let me access explicit interface implementation members (or default implementations) directly in case there's only one candidate? #9504
Unanswered
voroninp
asked this question in
Language Ideas
Replies: 3 comments 22 replies
-
To make it look at bit nicer you can access interface members through a property class MyClass : IFoo
{
private IFoo Foo => this;
void SomeMethod()
{
Foo.Bar();
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
-
If it were implemented, you could do private void Bar() : IFoo.Bar
{
} this.Bar(); |
Beta Was this translation helpful? Give feedback.
0 replies
-
No. The interface method may be reimplemented elsewhere (like in a derived class). So you have to call through the interface to ensure the right impl method is called. |
Beta Was this translation helpful? Give feedback.
21 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Right now, if I implement interface method explicitly, or when I want to call the default implementation, I need to cast type to the interface:
In case there's no ambiguity, and there's only one implementation of
Bar()
method, cannot compiler allow me accessing it without manually casting the type?Beta Was this translation helpful? Give feedback.
All reactions