public static void Serialize(ToDoList theList, string path) { using (Stream str = new FileStream(path, FileMode.Create)) { var binaryFormatter = new BinaryFormatter(); //we have to tempsave and reset the event handler, because the mainform is linked in it. a form is not serializeable ListChangedEventHandler oldHandler = theList.ListChanged; theList.ListChanged = null; binaryFormatter.Serialize(str, theList); //setting the event handler to it's old state theList.ListChanged = oldHandler; } }
private static ToDoList ConvertFromPre04(FormatPre04.TodoList list) { ToDoList result = new ToDoList(); foreach (FormatPre04.Category cat in list.Categories) { foreach (FormatPre04.Task t in cat.Tasks) { Task newTask = new Task(); newTask.Category = cat.Name; newTask.SetIsDone(true); newTask.DoneAt = t.DoneAt; newTask.Text = t.Text; result.AddTask(newTask); } } return(result); }