如何确定DoSomething()
调用该方法的底层接口?附加问题:我可以在 MyClass 构造函数中确定底层接口吗?我假设不是,因为它在实例化时是未知的,对吗?
编辑:我不是在寻找显式接口实现,而是在寻找一种不同的方式来确定底层接口。
public interface ITest
{
void DoSomething();
//....more methods
}
public interface IDecoy
{
void DoSomething();
//...more methods
}
public class MyClass : ITest, IDecoy
{
public void DoSomething()
{
//Question: How can I determine the underlying interface that called this method?
//at one time it is ITest, at another IDecoy. How can I figure out which one at each time?
}
}
public class Test
{
public Test()
{
ITest myClassInstance1 = new MyClass();
IDecoy myClassInstance2 = new MyClass();
myClassInstance1.DoSomething();
myClassInstance2.DoSomething();
}
}