如何解决使用对象值类型的子词典对词典进行排序
我有一个Argument of type '(event: E) => any' is not assignable to parameter of type 'T'.
'(event: E) => any' is assignable to the constraint of type 'T',but 'T' could be instantiated with a different subtype of constraint
'(event: E) => any'.ts(2345)
,需要根据子词典的某个值进行排序。
例如
Dictionary<string,Dictionary<string,object>>
带有键James和Tobi的字典需要根据temp值进行排序。 该方法将使用字符串“ Temp”表示要排序的键。
根据上下文的不同,对象值的类型会有所不同,但是该方法可以识别该类型,从而可以将对象分类为正确的类型以进行比较。
该解决方案无法创建特定的对象,因为字典
所有子词典将具有相同的“属性”,因此不具有该值的子词典将不会成为问题。
因此,在简单描述中,采用了以下方法:
{
"James": {
"Age": 21,"Surname": "Doe","Temp": 80.6
},"Tobi": {
"Age": 26,"Temp": 60.5
}
}
和
字符串“临时”
和可能的Temp类型
字符串“ double”
返回
{
"James": {
"Age": 21,"Temp": 60.5
},"Jessica": {
"Age": 18,"Surname": "Samms","Temp": 50.67
}
}
IEnumerable<KeyValuePair<string,object>>>
解决方法
这很容易,您可能甚至不需要知道类型,因为它会为您解决:
It.Is<System.Net.Http.HttpRequestMessage>(x => whatever specific equality conditions you want to match on)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。