IDictionary to/from Xml

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
 
Z

Zürcher See

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top