数据契约 +多维数组——有什么解决方案吗?
来自 MSDN:
组合集合类型(具有集合的集合)是 允许。锯齿状数组被视为集合的集合。 不支持多维数组。
那么,如果您无法正常序列化多维数组,如何有效地解决这个问题呢?我的想法是拥有一个属性来展平数组并序列化该集合并在反序列化期间将其展平,但我不确定这是否有效?
以前有人找到解决方案吗?
我应该注意到,我认为展平可能起作用的原因是因为我的尺寸是固定值(它们是硬编码的)。
From MSDN:
Combining collection types (having collections of collections) is
allowed. Jagged arrays are treated as collections of collections.
Multidimensional arrays are not supported.
So, if you can't normally serialize a multidimensional array, how does one get around this efficiently? My thought is to have a property that flattens the array and serialize that collection and unflatten it during deserialization, but I'm not sure if that's efficient?
Anyone find a solution this before?
I should note that the reason I think flattening might work is because my dimensions are a fixed value (they are hard-coded).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
是的,您可以将其压平或锯齿化,无论哪种更方便。
Yes, you could flatten it or Jagged-ize it, whatever is more convenient.
每当你遍历一个二维数组时,你都会花费 O(n) 的努力(或者输入中的每个项目一个“处理”单元)。正如您所说,在二维和一维之间进行转换并不麻烦。除非您处理的数据量非常大(Web 服务的调用频率的数组大小),或者在高度受限的系统(.Net Compact 或 .Net Micro Frameworks)上,否则我怀疑这确实是一个大问题。像排序这样的事情会变得昂贵。
Any time you rip through a 2-D array you're expending O(n) effort (or one "processing" unit per item in the input). It's not much trouble to convert between 2-D and 1-D and back as you said. Unless you're dealing in really high volumes (array size of call frequency of the web service), or on a highly constrained system (.Net Compact or .Net Micro Frameworks), I doubt this would really be a big issue. Things like sorting are what get expensive.
也许有一个扩展方法:
Maybe with an extension method: