コード例 #1
0
        public static Book SearchBook(this Library library, string title, string path)
        {
            BookType  bt      = BookType.None;
            XDocument xDoc    = XDocument.Load(path);
            var       newBook = new Book();
            var       element = xDoc.Root
                                .Elements("Books")
                                .Elements("Book")
                                .Where(b => ((string)b.Element("Name")).Equals(title))
                                .FirstOrDefault();

            if (element != null)
            {
                newBook = new Book(element.Element("Name").Value,
                                   element.Element("Author").Value,
                                   int.Parse(element.Element("Year").Value),
                                   bt.Parse(element.Element("Genre").Value));
            }
            return(newBook);
        }
コード例 #2
0
        public static List <Book> SelectBooksWhichContains(this Library lib, string foundValue, string path)
        {
            XDocument xDoc          = XDocument.Load(path);
            var       searchedBooks = new List <Book>();
            BookType  bt            = BookType.None;
            var       books         = xDoc.Root
                                      .Elements("Books")
                                      .Elements("Book")
                                      .Where(b => ((string)b.Element("Name")).Contains(foundValue));

            foreach (XElement element in books)
            {
                searchedBooks.Add(new Book(element.Element("Name").Value,
                                           element.Element("Author").Value,
                                           int.Parse(element.Element("Year").Value),
                                           bt.Parse(element.Element("Genre").Value)));
            }

            return(searchedBooks);
        }