Skip to content

Commit 2f74cb7

Browse files
ES-263734-Feedback addressed
1 parent ac7c2ac commit 2f74cb7

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

  • Bookmarks/Rename-bookmark/.NET/Rename-bookmark

Bookmarks/Rename-bookmark/.NET/Rename-bookmark/Program.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,16 @@ private static void ReplaceBookmarkName(WordDocument document, string existingBo
5252
WParagraph startParagraph = bookmark.BookmarkStart.Owner as WParagraph;
5353
// Find the index of the old bookmark start in the paragraph's child entities
5454
startIndex = startParagraph.ChildEntities.IndexOf(bookmark.BookmarkStart);
55-
// Insert the new bookmark end at the same index (if found)
56-
if (startIndex >= 0)
57-
startParagraph.ChildEntities.Insert(startIndex, newBookmarkStart);
55+
// Insert the new bookmark end at the same index.
56+
startParagraph.ChildEntities.Insert(startIndex, newBookmarkStart);
5857
}
5958
else if (bookmark.BookmarkStart != null && bookmark.BookmarkStart.Owner is InlineContentControl)
6059
{
6160
InlineContentControl startICC = bookmark.BookmarkStart.Owner as InlineContentControl;
6261
// Find the index of the old bookmark end in the ICC's paragraph items
6362
startIndex = startICC.ParagraphItems.IndexOf(bookmark.BookmarkStart);
64-
// Insert the new bookmark end at the same index (if found)
65-
if (startIndex >= 0)
66-
startICC.ParagraphItems.Insert(startIndex, newBookmarkStart);
63+
// Insert the new bookmark end at the same index.
64+
startICC.ParagraphItems.Insert(startIndex, newBookmarkStart);
6765
}
6866
// Determine the owner and index for the bookmark end.
6967
// Similar to start, the end could be in a paragraph or inline content control.
@@ -72,18 +70,16 @@ private static void ReplaceBookmarkName(WordDocument document, string existingBo
7270
WParagraph endParagraph = bookmark.BookmarkEnd.Owner as WParagraph;
7371
// Find the index of the old bookmark end in the paragraph's child entities
7472
endIndex = endParagraph.ChildEntities.IndexOf(bookmark.BookmarkEnd);
75-
// Insert the new bookmark end at the same index (if found)
76-
if (endIndex >= 0)
77-
endParagraph.ChildEntities.Insert(endIndex, newBookmarkEnd);
73+
// Insert the new bookmark end at the same index.
74+
endParagraph.ChildEntities.Insert(endIndex, newBookmarkEnd);
7875
}
7976
else if (bookmark.BookmarkEnd != null && bookmark.BookmarkEnd.Owner is InlineContentControl)
8077
{
8178
InlineContentControl endICC = bookmark.BookmarkEnd.Owner as InlineContentControl;
8279
// Find the index of the old bookmark end in the ICC's paragraph items
8380
endIndex = endICC.ParagraphItems.IndexOf(bookmark.BookmarkEnd);
84-
// Insert the new bookmark end at the same index (if found)
85-
if (endIndex >= 0)
86-
endICC.ParagraphItems.Insert(endIndex, newBookmarkEnd);
81+
// Insert the new bookmark end at the same index.
82+
endICC.ParagraphItems.Insert(endIndex, newBookmarkEnd);
8783
}
8884
//Removes the bookmark from Word document.
8985
document.Bookmarks.Remove(bookmark);

0 commit comments

Comments
 (0)