问题:我使用可序列化字典类(位于 http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx )来序列化字典。效果很好,但我遇到了一个烦人的问题。
<System.Xml.Serialization.XmlRoot("DataBase")> _
Public Class cDataBase
<System.Xml.Serialization.XmlNamespaceDeclarations()> _
Public ns As New System.Xml.Serialization.XmlSerializerNamespaces()
<System.Xml.Serialization.XmlElement("Tables")> _
Public Tables1 As New SerializableDictionary(Of String, cTable)
End Class ' cDataBase
当我序列化上述类的实例时,创建的 xml 如下所示:
<Tables>
<item>
<key>
<string>MyTable</string>
</key>
<value>
<Table CreationDate="0001-01-01T00:00:00" LastModified="0001-01-01T00:00:00">
<Columns>
<Column Name="PrimaryKeyName">
<DataType>Uniqueidentifier</DataType>
<Length>36</Length>
</Column>
</Columns>
<Rows>
<Row>
<Item>Reihe1</Item>
<Item>Reihe2</Item>
<Item>Reihe3</Item>
</Row>
<Row>
<Item>Reihe1</Item>
<Item>Reihe2</Item>
<Item>Reihe3</Item>
</Row>
如果我能弄清楚如何将键从 <string> 重命名为属性中定义的东西,那会很好
<key>
<string>MyTable</string>
</key>
基本上类似于 XmlArrayItem 属性,如下所示,如果(仅)字典是一个数组......
<System.Xml.Serialization.XmlArray("Tables")> _
<System.Xml.Serialization.XmlArrayItem("Table")> _
Public Tables As New List(Of cTable)
我想尝试将字符串更改为从字符串继承的自定义类,我可以为其配备一个名称,但问题是,不能从字符串继承......