Exemplo n.º 1
0
        public TodoList LoadTodoList(string path)
        {
            var         todos = new List <Todo>();
            XmlDocument xDoc  = new XmlDocument();

            xDoc.Load(path);
            foreach (XmlNode todoElem in xDoc.DocumentElement)
            {
                var data = new Dictionary <string, string>();
                foreach (XmlNode dataNode in todoElem.ChildNodes)
                {
                    if (dataNode.Name == "Tags")
                    {
                        StringBuilder stringBuilder = new StringBuilder();

                        foreach (XmlNode tagNode in dataNode.ChildNodes)
                        {
                            stringBuilder.Append(tagNode.InnerText).Append(" ");
                        }

                        data.Add("Tags", stringBuilder.ToString().Trim());
                    }
                    else
                    {
                        data.Add(dataNode.Name, dataNode.InnerText);
                    }
                }
                todos.Add(Todo.CreateTodoFromInfo(data));
            }

            return(new TodoList(todos));
        }
        public TodoList LoadTodoList(string path)
        {
            return(new TodoList(XDocument.Load(path).Descendants("Todo").Select(elem =>
                                                                                Todo.CreateTodoFromInfo(
                                                                                    elem.Elements().Select(e => {
                string value = e.Value.ToString();
                if (e.Name == "Tags")
                {
                    value = string.Join(' ', e.Elements().Select(tag => tag.Value));
                }

                return new[] { e.Name.ToString(), value };
            }).ToDictionary(field => field[0], field => field[1]))
                                                                                ).ToList()));
        }