如果你考虑:
class A : IInterface { }
在运行时:
A instance = new A();
instance.GetType(); // returns "A"
或
IInterface instance = new A();
instance.GetType(); // returns "A"
或
object instance = new A();
instance.GetType(); // returns "A"
问题:如何获取 IInterface
作为类型?
最佳答案
instance.GetType().GetInterfaces()
将获取实例类型实现或继承的所有接口(interface) (Type.GetInterfaces Method) .
关于c# - 在运行时获取继承的对象类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6439902/