组合两种匿名类型
我之前问过相关问题并得到了很好的答复 我如何定义匿名类型?< /a>
但现在我想知道是否可以组合两种匿名类型
基本上我在缓存中存储一些每周数据,就像我在相关问题中描述的那样
所以如果我将匿名类型
存储为object
它包含本周的一些数据 我想每天将今天的数据附加到该对象。
因此,我从一侧将匿名类型
中的数据作为对象
,从另一侧我有完全相同的结构化匿名类型
,并且我想要附加/将新的匿名类型
中的数据添加到旧的匿名类型
作为对象
并将其放回缓存。
如果您查看我的相关问题,我的匿名类型看起来像这样:
var jsonData = new { total = 0, page = 0, records = 0,
rows = new[] { new { dummy = "" } };
那么问题是我如何在我的情况下组合匿名类型?
例如,如果它是两个集合,我会这样做
List<Data> weeklyFromCahce = GetFromCache()
List<Data> todaysToCahce = GetFromDataBase();
,然后循环遍历 todaysToCahce
并将每个项目添加到 weeklyFromCahce
并更新 weeklyFromCahce
代码>返回缓存。
所以我想做类似的过程,但在我的例子中使用匿名类型。组合结果应该是匿名类型
,其中包含每周数据+当天数据,并且我使用新的匿名类型
更新缓存,该新匿名类型
将包含两个匿名实例的组合结果。
I asked the related question before and get gretat ansfer on that How could i define anonymous type?
But now i am wondering is it possible to combine two anonymous types
Basically i am storing some weekly data in cache like i described in related queston
So in case i have anonymous type
stored as object
it is contain some data for current week
and i want to append today's data to that object everyday.
So i have data in anonymous type
as object
from one side and from another i have completely the same structured anonymous type
and i want do append/add data from my new anonymous type
to the old one which is anonymous type
as object
and put it back to cache.
If you would look my related question my anonymous type looking like that:
var jsonData = new { total = 0, page = 0, records = 0,
rows = new[] { new { dummy = "" } };
So the question is how could i combine anonymous types in my case?
For example if it would be two collections i would go like that
List<Data> weeklyFromCahce = GetFromCache()
List<Data> todaysToCahce = GetFromDataBase();
and than i would loop though todaysToCahce
and add each item to weeklyFromCahce
and that put updated weeklyFromCahce
back to cache.
So i want to do similar process but with anonymous types in my case. The combined result should be the anonymous type
which would contain weekly data + current day data and that i update cache with the new anonymous type
which would contain combined result of two anonymous instances.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
?
在 TS 评论后更新
更新 2
不确定它是否适合您的情况,但仍然有效。
?
Updated after TS comment
Update 2
Not exactly sure if it's acceptable in your case, but still it works.