If we have two interfaces with a common base that a class must implement, is it possible to explicitly implement the common base?
Consider IEnumerable<T>
for example:
public class MyMultiEnumerable: IEnumerable<int>, IEnumerable<double>
{
private readonly List<int> intList = new List<int>();
private readonly List<double> doubleList = new List<double>();
IEnumerator<double> IEnumerable<double>.GetEnumerator()
{
return doubleList.GetEnumerator();
}
IEnumerator<int> IEnumerable<int>.GetEnumerator()
{
return intList.GetEnumerator();
}
public IEnumerator GetEnumerator()
{
/*
* How do we deal with this common case, where in context it means
* two different things?
*/
throw new System.NotImplementedException();
}
}
I have no requirement to do so, but I am interested from a theoretical perspective.
Update #1
I think my use of IEnumerable
and basic types is conflating this, and after thinking about it some more, I believe it could be stripped back to this problem:
public interface CommonBase
{
void CommonMethod();
}
public interface AltBase1 : CommonBase
{
void UnommonMethod();
}
public interface AltBase2 : CommonBase
{
void UnommonMethod();
}
public class Example : AltBase1, AltBase2
{
public void CommonMethod()
{
/*
* If this method needs to know whether it is being called on behalf
* of AltBase1 or AltBase2, how could it determine the implementation?
*/
}
void AltBase2.UnommonMethod()
{
}
void AltBase1.UnommonMethod()
{
}
}
Because it doesn't appear possible to explicitly implement an interface's inherited members (Example of how this might look below). I strongly believe this isn't possible via any conventional means, as it appears to be a multiple inheritance problem.
void AltBase1.CommonBase.CommonMethod()
{
// AltBase1 targeted Implementation
}
Could it be achieved via any Meta-based approach, or not at all?