質問: 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)
Of String を、名前を付けることができる、string から継承されたカスタム クラスに変更したかったのですが、問題は、string から継承できないことです...