If we have the following sample application:
interface ITest
{
string Test { get; }
}
class A : ITest
{
string ITest.Test { get { return "Test from A!"; } }
}
class B : A, ITest
{
string ITest.Test { get { return "Test from B!"; } }
}
Given an instance of B, is it possible to access A’s implementation of ITest?
For example:
B b = new B();
ITest test = b;
string value = test.Test; // "Test from B!"
A a = b;
test = a;
value = test.Test; // Still "Test from B!"
Note, this is no real world problem but more of a general wondering.
No, it’s not. At least not normally – it’s possible that you could do it with reflection.
Basically, by reimplementing
ITest,Bis saying that it’s taking complete responsibility for the implementation ofITest.Testwithin any object of typeB– and you can’t even call it from withinBwhich you’d normally be able to if you were overriding in the usual way.EDIT: I’ve just proved (in a hacky way) that you can call it with reflection:
This prints out “Base”. It’s pretty horrible though – I’d have to be desperate to do it…