我正在尝试检查以下内容
typeof( ICollection<> ).GetTypeInfo().IsAssignableFrom( targetProperty.PropertyType.GetTypeInfo() )
传入的参数IsAssignableFrom
是一个IList<Something>
. 但它返回错误。
以下也返回false。
typeof( ICollection<> ).GetTypeInfo().IsAssignableFrom( targetProperty.PropertyType.GetTypeInfo().GetGenericTypeDefinition() )
甚至以下内容也返回错误。
typeof( ICollection<> ).GetTypeInfo().IsAssignableFrom( typeof(IList<>) )
后者不应该绝对返回true吗?
targetProperty.PropertyType
当可以是任何类型时,我怎样才能得到正确的结果?它可以是 a List<T>
、 an ObservableCollection<T>
、 a ReadOnlyCollection<T>
、自定义集合类型等。