我想检查以下内容
typeof( ICollection<> ).GetTypeInfo().IsAssignableFrom( targetProperty.PropertyType.GetTypeInfo() )
Run Code Online (Sandbox Code Playgroud)
传入的参数IsAssignableFrom是一个IList<Something>.但它正在返回虚假.
以下内容也返回false.
typeof( ICollection<> ).GetTypeInfo().IsAssignableFrom( targetProperty.PropertyType.GetTypeInfo().GetGenericTypeDefinition() )
Run Code Online (Sandbox Code Playgroud)
即使以下情况也会返回false.
typeof( ICollection<> ).GetTypeInfo().IsAssignableFrom( typeof(IList<>) )
Run Code Online (Sandbox Code Playgroud)
难道后者肯定会回归真实吗?
如果targetProperty.PropertyType可以是任何类型,我怎样才能得到正确的结果?它可以是a List<T>,a ObservableCollection<T>,a ReadOnlyCollection<T>,自定义集合类型等.