假设我有一类像如何确定一类具有实现特定接口或不
interface ISampleInterface
{
void SampleMethod();
}
class ImplementationClass : ISampleInterface
{
// Explicit interface member implementation:
void ISampleInterface.SampleMethod()
{
// Method implementation.
}
static void Main()
{
// Declare an interface instance.
ISampleInterface obj = new ImplementationClass();
// Call the member.
obj.SampleMethod();
}
}
从主要方法我怎么能确定ImplementationClass
类写作类似下面
ISampleInterface
SampleInterface obj = new ImplementationClass();
obj.SampleMethod();
有什么办法....请讨论。谢谢。使用
好如果你需要知道这一点,推测在执行时你有* *东西*你有一个对象,或只是类型的名称,或者是什么? –
Erm看代码或元数据类 –
@JonSkeet也许我错了,但我认为OP是问如何在设计时确定它。 –