/// <summary> /// Does repeatedly do <see cref="Pop"/> operations, until and including the /// element given in the argument. /// </summary> /// <param name="element">The element.</param> /// <exception cref="ArgumentNullException">element</exception> /// <exception cref="InvalidOperationException">Could not pop to element " + element.ToString()</exception> public void PopTo(OpenXmlCompositeElement element) { if (null == element) { throw new ArgumentNullException(nameof(element)); } OpenXmlCompositeElement ele = null; while (_currentElementStack.Count > 0) { ele = Pop(); if (object.ReferenceEquals(ele, element)) { break; } } if (ele != element) { throw new InvalidOperationException("Could not pop to element " + element.ToString()); } }
/// <summary> /// Does repeatedly do <see cref="Pop"/> operations, until but excluding the /// element given in the argument. /// </summary> /// <param name="element">The element.</param> /// <exception cref="ArgumentNullException">element</exception> /// <exception cref="InvalidOperationException">Could not pop to before element " + element.ToString()</exception> public void PopToBefore(OpenXmlCompositeElement element) { if (null == element) { throw new ArgumentNullException(nameof(element)); } while (_currentElementStack.Count > 0) { if (object.ReferenceEquals(_currentElementStack[_currentElementStack.Count - 1], element)) { break; } Pop(); } if (_currentElementStack.Count == 0) { throw new InvalidOperationException("Could not pop to before element " + element.ToString()); } }