为什么没有一个XML序列化的词典.NET?词典、序列化、XML、NET

2023-09-02 10:17:24 作者:哥的霸氣荍不住

我需要一个XML序列化的字典。其实,我现在有两个需要一种比较不同的程序。我非常惊讶地看到,.NET不具备的。我问的问题在其他地方得到了讽刺的反应。我不明白为什么这是一个愚蠢的问题。

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.

能有人开导我,给不同的.NET功能如何依赖都在XML序列化,为什么没有一个XML序列化的字典。希望你也可以解释为什么有些人认为这是一个愚蠢的问题。我想我一定是失去了一些东西根本,我希望你将能够填补国内空白。

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.

推荐答案

有关XML序列化的事情是,它不只是有关创建字节流。这也是关于创建一个XML Schema的字节这个流将验证对。有没有在XML模式没有很好的办法来重新present一本字典。你可以做的最好的是要表明,有一个独特的密钥。

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.