|
One little thing I'd like to see changed in C# |
2004-01-28 |
|
I love explicit interface implementation in .NET, where a method defined on an interface can only be called through a reference to that type.
public interface IFoo {
void DoFoo();
}
public class Bar : IFoo {
void IFoo.DoFoo() {
...
}
}
This forces Bar clients to program against the IFoo interface, which makes implementation substitution an easy process. Sounds good so far? It is, until I want to call DoFoo() from within Bar. Instead of making a regular call to DoFoo(); Or even IFoo.DoFoo(); I have to go to the trouble of casting 'this' to IFoo (this as IFoo).DoFoo(); Under the covers, the explicit interface implementation method is compiled as a private method with the name interfaceName.methodName. The code I use to call this (above) corresponds pretty well to the IL that I need to invoke the method, but it seems like a little bit of extra typing. Can't the compiler do this for me? |
|