Prev: Urgent! Global and Very Successful company needs C# Developer!
Next: disinclude from xml serialization
From: John Grandy on 5 May 2010 14:52 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 5 May 2010 15:37 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 5 May 2010 15:47
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>. |