我正在尝试将System.Linq.Dynamic.Core与ImmutableArray一起用于动态OrderBy,但我得到了以下异常:
Expression of type 'System.Collections.Immutable.ImmutableArray`1[$customType]' cannot be used for parameter of type 'System.Collections.Generic.IEnumerable`1[$customType]' of method 'System.Linq.IOrderedEnumerable`1[$customType] OrderByDescending[$customType,Int32](System.Collections.Generic.IEnumerable`1[$customType], System.Func`2[$customType,System.Int32])' (Parameter 'arg0')
为什么会这样呢?他们是否为不可变类型定义了特定的验证?普通的OrderBy完全有能力对其进行排序。这是否应该作为功能请求提交给他们,或者我是否遗漏了一些明显的东西?一旦它被添加到列表中,它就像一个护身符一样起作用。
发布于 2020-09-02 07:17:10
这似乎是.Net (核心)中的一个错误,特别是在验证Expression.Call的参数时。
最终,第一个参数通过调用TypeUtils.AreReferenceAssignable进行验证,代码假设值类型不能(引用)赋值给非值类型,并且ImmutableArray是一个值类型,因为它是用struct实现的。
我在github上打开了an issue,看看别人是怎么想的。
https://stackoverflow.com/questions/63691603
复制相似问题