基本的に私は を含む を持ってDataContract
いますDictionary
:
[DataContract]
public class MyDictionary : IDictionary<string, object> {
[DataMember(Name = "Data")]
protected IDictionary<string, object> Dictionary { get; private set; }
// ...
}
XML 出力の関連部分を次に示します。
<Data>
<a:KeyValueOfstringanyType>
<a:Key>ID</a:Key>
<a:Value i:type="s:int">2</a:Value>
</a:KeyValueOfstringanyType>
<a:KeyValueOfstringanyType>
<a:Key>Value</a:Key>
<a:Value i:type="s:int">4711</a:Value>
</a:KeyValueOfstringanyType>
</Data>
出力を次のように簡略化するにはどうすればよいですか。
<Data>
<ID i:type="s:int">2</ID>
<Value i:type="s:int">4711</Value>
</Data>
ディクショナリ キーは文字列に制限されているため、ASCII 以外のキーを使用するというばかげた考えを誰も得なければ、正常に機能するはずです。CollectionDataContract
必要なものに少し近づいた属性を見つけましたが、キーと値のペアが完全に保存され、メモリが浪費されます。多分それはクラスを愛することは可能ISerializable
ですが、それがDataContractSerializer
. ちなみに、このソリューションはDataContractJsonSerializer
.