// Use an iterator and a visitor to print info of every bookmark in the collection. private static void PrintAllBookmarkInfo(BookmarkCollection bookmarks) { BookmarkInfoPrinter bookmarkVisitor = new BookmarkInfoPrinter(); // Get each bookmark in the collection to accept a visitor that will print its contents. using (IEnumerator <Bookmark> enumerator = bookmarks.GetEnumerator()) { while (enumerator.MoveNext()) { Bookmark currentBookmark = enumerator.Current; if (currentBookmark != null) { currentBookmark.BookmarkStart.Accept(bookmarkVisitor); currentBookmark.BookmarkEnd.Accept(bookmarkVisitor); Console.WriteLine(currentBookmark.BookmarkStart.GetText()); } } } }
/// <summary> /// Use an iterator and a visitor to print info of every bookmark from within a document. /// </summary> private static void PrintAllBookmarkInfo(Document doc) { // Create a DocumentVisitor BookmarkInfoPrinter bookmarkVisitor = new BookmarkInfoPrinter(); // Get all bookmarks from the document BookmarkCollection bookmarks = doc.Range.Bookmarks; // Get the enumerator from the document's BookmarkCollection and iterate over the bookmarks IEnumerator enumerator = bookmarks.GetEnumerator(); while (enumerator.MoveNext()) { Bookmark currentBookmark = (Bookmark)enumerator.Current; // Accept our DocumentVisitor it to print information about our bookmarks currentBookmark.BookmarkStart.Accept(bookmarkVisitor); currentBookmark.BookmarkEnd.Accept(bookmarkVisitor); // Prints a blank line Console.WriteLine(currentBookmark.BookmarkStart.GetText()); } }
/// <summary> /// Use an iterator and a visitor to print info of every bookmark from within a document. /// </summary> private static void PrintAllBookmarkInfo(BookmarkCollection bookmarks) { // Create a DocumentVisitor BookmarkInfoPrinter bookmarkVisitor = new BookmarkInfoPrinter(); // Get the enumerator from the document's BookmarkCollection and iterate over the bookmarks using (IEnumerator <Bookmark> enumerator = bookmarks.GetEnumerator()) { while (enumerator.MoveNext()) { Bookmark currentBookmark = enumerator.Current; // Accept our DocumentVisitor it to print information about our bookmarks if (currentBookmark != null) { currentBookmark.BookmarkStart.Accept(bookmarkVisitor); currentBookmark.BookmarkEnd.Accept(bookmarkVisitor); // Prints a blank line Console.WriteLine(currentBookmark.BookmarkStart.GetText()); } } } }