Bry*_*son 4 c# system.reflection base-class-library portable-class-library
我已经阅读了Evolving the Reflection API博客文章,并且当我在PCL中包含"旧"API时,我已经转换了大部分代码,但我无法找到IsInstanceOfType或等同于Type或TypeInfo.它是非常常用的,所以我怀疑它是在新的API下完全丢弃所以我打赌功能刚刚被重命名或折叠在一起其他功能,我只是没有看到它.
小智 6
使用此扩展方法:
public static bool IsInstanceOfType(this Type type, object obj){
return obj != null && type.GetTypeInfo().IsAssignableFrom(obj.GetType().GetTypeInfo());
}
Run Code Online (Sandbox Code Playgroud)