0

我正在尝试将 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 完全有能力对其进行排序。这应该作为功能请求提交给他们,还是我遗漏了一些明显的东西?一旦它被投射到一个列表中,它就像一个魅力。

4

1 回答 1

1

这似乎是 .Net (Core) 中的一个错误,特别是在验证 .Net 的参数时Expression.Call

最终,第一个参数通过调用进行验证,TypeUtils.AreReferenceAssignable并且代码假定值类型不能(引用)分配给非值类型,并且ImmutableArray是值类型,因为它是用struct.

我在 github 上打开了一个 issue,看看其他人是怎么想的。

于 2020-09-01T23:17:09.713 回答