Hi

Here's a bit of code working perfectly on a PC, but when running it on M4A,
the deserialized object contains 0 items, not 2.

            CallHistoryModel.Instance.AddItem(new CallHistoryItem { Number =
"1234", Type = CallHistoryItemType.OutgoingAnswered });
            CallHistoryModel.Instance.AddItem(new CallHistoryItem { Number =
"2345", Type = CallHistoryItemType.OutgoingAnswered });

            XmlSerializer x = new
XmlSerializer(CallHistoryModel.Instance.GetType());
            StringWriter o = new
StringWriter(System.Globalization.CultureInfo.InvariantCulture);
            x.Serialize(o, CallHistoryModel.Instance);
            string serializedData = o.GetStringBuilder().ToString();

            x = new XmlSerializer(CallHistoryModel.Instance.GetType());
            StringReader sr = new StringReader(serializedData);
            CallHistoryModel ch = (CallHistoryModel)x.Deserialize(sr);
if (ch.History.Count == 0)
Console.WriteLine("FAIL");

And the objects I'm serializing

    [Serializable]
    public class CallHistoryModel
    {
        private static CallHistoryModel me;
        private static object myLock = new object();

        public static CallHistoryModel Instance
        {
            get
            {
                if (me == null)
                {
                    lock (myLock)
                    {
                        if (me == null)
                            me = new CallHistoryModel();
                    }
                }
                return me;
            }
        }

        private List<CallHistoryItem> history;
        public List<CallHistoryItem> History
        {
            get { return history; }
            set { history = value; }
        }

        public ObservableCollection<CallHistoryItem> Items
        {
            get
            {
                lock (myLock)
                {
                    return new
ObservableCollection<CallHistoryItem>(history);
                }
            }
        }

        public void AddItem(CallHistoryItem item)
        {
            if (history.Count >= 100)
                history.RemoveRange(100, history.Count - 100);
            history.Add(item);
        }

        public void RemoveItem(CallHistoryItem item)
        {
            history.Remove(item);
        }

        public CallHistoryModel()
        {
            history = new List<CallHistoryItem>();
        }


    }

    [Serializable]
    public class CallHistoryItem
    {
        public string Number { get; set; }
        public string Name { get; set; }
        public DateTime Date { get; set; }
        public CallHistoryItemType Type { get; set; }
        public byte Count { get; set; }

        public CallHistoryItem(string number)
        {
            Number = number;
            Date = DateTime.Now;
        }

        public CallHistoryItem()
        {
        }
    }


    public enum CallHistoryItemType { OutgoingUnanswered, OutgoingAnswered,
IncomingUnanswered, IncomingAnswered }


Is there a trick to get this to work or do I have to resort to manual xml
parsing?

Regards
Stephan



--
View this message in context: 
http://mono-for-android.1047100.n5.nabble.com/Deserialization-issue-List-MyType-not-being-filled-tp5711738.html
Sent from the Mono for Android mailing list archive at Nabble.com.
_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to