我有一些非常复杂的对象传递给我的回调,我不控制对象设计,也不知道在那里会发生什么。我所知道的是,它可能实现了SpecificInterface
接口,该接口具有SpecificProperty
公共属性的公共getter。
我有这段代码:
dynamic theObjectPassed = ...;
Type objectType = theObjectPassed.GetType();
var objectProperty = objectType.GetProperty("SpecificProperty");
Type interfaceType = objectType.GetInterface("SpecificInterface");
var interfaceProperty = interfaceType.GetProperty("SpecificProperty");
以某种方式objectProperty
变为null
,但interfaceProperty
变为非空。
为什么在接口中找到属性,而不是从该接口派生的类中找到属性?