From: John Grandy on
I wish MyClass to be serializable to xml. What do I need to do to
accomplish this ? Thanks.



public class MyClass
{

Dictionary<MyEnum, MyItem> _myItems;
// etc.

public Dictionary<MyEnum, MyItem> MyItems
{
get { return _myItems; }
}

// etc.
}


public class MyItem
{
MyEnum _enumValue;
string _stringValue;
// etc.

public MyEnum EnumValue
{
get { return _myEnum; }
set { _myEnum = value; }
}

public string StringValue
{
get { return _stringValue; }
set { _stringValue = value; }
}

// etc.
}


public enum MyEnum
{
Value1 = 1,
// etc
}



From: Family Tree Mike on
On 5/5/2010 2:52 PM, John Grandy wrote:
> I wish MyClass to be serializable to xml. What do I need to do to
> accomplish this ? Thanks.
>
>
>
> public class MyClass
> {
>
> Dictionary<MyEnum, MyItem> _myItems;
> // etc.
>
> public Dictionary<MyEnum, MyItem> MyItems
> {
> get { return _myItems; }
> }
>
> // etc.
> }
>
>
> public class MyItem
> {
> MyEnum _enumValue;
> string _stringValue;
> // etc.
>
> public MyEnum EnumValue
> {
> get { return _myEnum; }
> set { _myEnum = value; }
> }
>
> public string StringValue
> {
> get { return _stringValue; }
> set { _stringValue = value; }
> }
>
> // etc.
> }
>
>
> public enum MyEnum
> {
> Value1 = 1,
> // etc
> }
>
>
>

Dictionarys are not xmlserializable, but there are a number of options
online as to how to serialize the data. I know that there is a
SerializableDictionary class that has code posted online if you search
for it. You could serialize the individual dictionary items and rebuild
the dictionary on deserialization as another option.

--
Mike
From: Mr. Arnold on
John Grandy wrote:
> I wish MyClass to be serializable to xml. What do I need to do to
> accomplish this ? Thanks.
>
>

At best, the only thing you can serialize is MyItem.

http://blogs.msdn.com/psheill/archive/2005/04/09/406823.aspx

The other thing you can do is load MyItem into a List<T> and XML
serialize the List<T>.