首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么System.Linq.Dynamic.Core OrderBy不能与ImmutableArray一起工作?

为什么System.Linq.Dynamic.Core OrderBy不能与ImmutableArray一起工作?
EN

Stack Overflow用户
提问于 2020-09-02 00:18:23
回答 1查看 225关注 0票数 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完全有能力对其进行排序。这是否应该作为功能请求提交给他们,或者我是否遗漏了一些明显的东西?一旦它被添加到列表中,它就像一个护身符一样起作用。

EN

Stack Overflow用户

回答已采纳

发布于 2020-09-02 07:17:10

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

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

我在github上打开了an issue,看看别人是怎么想的。

票数 1
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63691603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档