IDictionary to/from Xml

  • Thread starter Thread starter Kimmo Laine
  • Start date Start date
K

Kimmo Laine

Hi,

is there a way to serialize/deserialize IDictionary data to Xml. Something
like this:

public MyDictionary: DictionaryBase {
public MyDictionary() :base() {}
public void Add( string key, object val ) {
Dictionary.Add( key, val );
}
public object Get( string key ) {
return Dictionary.Get( key );
}
public void FromXml( string xml ) {
Dictionary.Clear();
// . . .
}
public string ToXml() {
// . . .
}
}

// . . .
public enum MyEnum {
Item1 = 1,
Item2
}

public void Foo() {
MyEnum val1 = MyEnum.Item1;

MyDictionart md = new MyDictionary();
md.Add( "dummy1", 321 );
md.Add( "dummy2", val1 );

SendXmlSomewhere( md.ToXml() );

// . . .
md.FromXml( GetXmlSomewhere() );

MyEnum val2 = ( MyEnum )md.Get( "itemname" );
}



thx

Kimmo Laine
 
I don't know if it works but you can create an xml and serialize
(BinaryFormatter class) the objects in a cdata tag

<dictionary>
<item name="dummy1">
<![cdata[ ... ]]>
</item>
<item name="dummy2">
<![cdata[ ... ]]>
</item>
</dictionary>

But you have also to implement a "FromXml()" method.
 
Back
Top