Discussion: implement interface members with different names #546
Replies: 9 comments
-
What about overriding base class members with different names? |
Beta Was this translation helpful? Give feedback.
-
@orthoxerox I didn't find any use cases for that and I'm not sure if clr supports it. |
Beta Was this translation helpful? Give feedback.
-
@alrz It definitely supports it. |
Beta Was this translation helpful? Give feedback.
-
I find the Why not
|
Beta Was this translation helpful? Give feedback.
-
Well, it means "implements" (and extends/inherits) in C#
Someday. |
Beta Was this translation helpful? Give feedback.
-
I get that this just exposes an existing capability of .Net, but isn't the workaround of calling a renamed member from an explicitly implemented one sufficient? class Class : Interface<A>, Interface<B>
{
public A PropertyA { get; }
public B PropertyB { get; }
public void MethodA() {}
public void MethodB() {}
A Interface<A>.Property => PropertyA;
B Interface<B>.Property => PropertyB;
void Interface<A>.Method() => MethodA();
void Interface<B>.Method() => MethodB();
} I get that the above code is tedious and fairly verbose and that the generated assembly will not be exactly the same as with this proposal. But I don't think this happens often enough that it would be worth decreasing the verbosity. And the differences in the generated assembly probably won't cause any issues. So this doesn't seem worth doing to me. |
Beta Was this translation helpful? Give feedback.
-
@svick You need to forward every parameter to the target method. VB just emits |
Beta Was this translation helpful? Give feedback.
-
For this one, I think the best solution doesn't involve changing the language specification at all. Just have the compiler generate the equivalent of |
Beta Was this translation helpful? Give feedback.
-
I'd still prefer being explicit about my intents than allowing language magic. Than somebody can be lot surprise why reflection cannot find such a member. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Similar to
Implements
clause in VB:Open question: should we disrespect access modifiers when we are explicitly implementing a member? (VB does)
Beta Was this translation helpful? Give feedback.
All reactions