为什么.NET中没有XML序列化字典? [英] Why isn't there an XML-serializable dictionary in .NET?

查看:181
本文介绍了为什么.NET中没有XML序列化字典?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个XML可序列化的字典。其实我现在有两个完全不同的程序需要一个。我相当惊讶地发现.NET没有.NET。我在其他地方问了这个问题,并得到了讽刺的回应。我不明白为什么这是一个愚蠢的问题。



有人可以启发我,鉴于各种.NET功能如何依赖于XML序列化,为什么没有XML可串行字典希望你也可以解释为什么有些人认为这是一个愚蠢的问题。我想我一定是错过了一些基本的东西,希望能填补空白。

解决方案

关于XML序列化的事情是,它不仅仅是创建一个字节流。这也是关于创建一个XML模式,这个字节流将验证。 XML Schema中没有一个很好的方式来表示一个字典。你可以做的最好的就是显示一个唯一的键。



你可以随时创建自己的包装器,例如序列化字典的一种方法


I need an XML-serializable dictionary. Actually, I now have two quite different programs that need one. I was rather surprised to see that .NET doesn't have one. I asked the question elsewhere and got sarcastic responses. I don't understand why it's a stupid question.

Can someone enlighten me, given how dependent various .NET features are on XML serialization, why there isn't an XML-serializable dictionary. Hopefully, you can also explain why some people consider that a daft question. I guess I must be missing something fundamental and I'm hoping you'll be able to fill in the gaps.

解决方案

The thing about XML Serialization is that it's not just about creating a stream of bytes. It's also about creating an XML Schema that this stream of bytes would validate against. There's no good way in XML Schema to represent a dictionary. The best you could do is to show that there's a unique key.

You can always create your own wrapper, for instance One Way to Serialize Dictionaries.

这篇关于为什么.NET中没有XML序列化字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆