public static bool DeleteChildren(this BaseElementNavigator nav) { var parent = nav.Bookmark(); if (nav.MoveToFirstChild()) { while (!nav.IsAtBookmark(parent)) nav.DeleteTree(); } return true; }
public static IEnumerable<Bookmark> Find(this BaseElementNavigator nav, string path) { var parts = path.Split('.'); var bm = nav.Bookmark(); nav.Reset(); var result = locateChildren(nav, parts, partial: false); nav.ReturnToBookmark(bm); return result; }
public static bool MoveToPrevious(this BaseElementNavigator nav, string name) { var bm = nav.Bookmark(); while (nav.MoveToPrevious()) { if (nav.PathName == name) return true; } nav.ReturnToBookmark(bm); return false; }
/// <summary> /// Counts the number of bytes between the current position and the first occurrence of any of the target byte sequences. /// The starting position is returned to once a target is found or the end of the stream is reached. /// </summary> public static long CountBytesUntilAny(this Stream stream, byte[][] targets, out byte[] targetFound) { using (var start = stream.Bookmark()) { targetFound = stream.SeekEndOfAny(targets); var end = stream.Position; var count = end - start.Position; if (targetFound != null) count -= targetFound.Length; return count; } }
public static bool AppendChild(this BaseElementNavigator nav, Profile.ElementComponent child) { var bm = nav.Bookmark(); if (nav.MoveToFirstChild()) { while (nav.MoveToNext()) ; var result = nav.InsertAfter(child); if(!result) nav.ReturnToBookmark(bm); return result; } else { return nav.InsertFirstChild(child); } }