From: Oleg T. <he...@us...> - 2005-10-29 21:13:25
|
Update of /cvsroot/mvp-xml/Common/v2/src/XPath In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22746/v2/src/XPath Modified Files: XPathNavigatorIterator.cs Added Files: EmptyXPathNodeIterator.cs SingletonXPathNodeIterator.cs Log Message: Index: XPathNavigatorIterator.cs =================================================================== RCS file: /cvsroot/mvp-xml/Common/v2/src/XPath/XPathNavigatorIterator.cs,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- XPathNavigatorIterator.cs 25 Oct 2005 21:33:44 -0000 1.2 +++ XPathNavigatorIterator.cs 29 Oct 2005 21:13:10 -0000 1.3 @@ -44,7 +44,36 @@ public XPathNavigatorIterator(XPathNavigator navigator) : this() { _navigators.Add(navigator); - } + } + + /// <summary> + /// Initializes a new instance of the <see cref="XPathNavigatorIterator"/> + /// using given list of navigators. + /// </summary> + public XPathNavigatorIterator(XPathNodeIterator iterator) + : this(iterator, false) { } + + /// <summary> + /// Initializes a new instance of the <see cref="XPathNavigatorIterator"/> + /// using given list of navigators. + /// </summary> + public XPathNavigatorIterator(XPathNodeIterator iterator, bool removeDuplicates) + : this() { + XPathNodeIterator it = iterator.Clone(); + + while (it.MoveNext()) + { + if (removeDuplicates) + { + if (this.Contains(it.Current)) + { + continue; + } + } + + this.Add(it.Current.Clone()); + } + } /// <summary> /// Initializes a new instance of the <see cref="XPathNavigatorIterator"/> @@ -104,6 +133,64 @@ } } + /// <summary> + /// Determines whether the list contains a navigator positioned at the same + /// location as the specified XPathNavigator. This + /// method relies on the IsSamePositon() method of the XPathNavightor. + /// </summary> + /// <param name="value">The object to locate in the list.</param> + /// <returns>true if the object is found in the list; otherwise, false.</returns> + public bool Contains(XPathNavigator value) + { + foreach (XPathNavigator nav in _navigators) + { + if (nav.IsSamePosition(value)) + { + return true; + } + } + return false; + } + + /// <summary> + /// Determines whether the list contains a navigator whose Value property matches + /// the target value + /// </summary> + /// <param name="value">The value to locate in the list.</param> + /// <returns>true if the value is found in the list; otherwise, false.</returns> + public bool ContainsValue(string value) + { + + foreach (XPathNavigator nav in _navigators) + { + if (nav.Value.Equals(value)) + { + return true; + } + } + return false; + } + + + /// <summary> + /// Gets or sets the element at the specified index + /// </summary> + public XPathNavigator this[int index] + { + get { return _navigators[index]; } + set { _navigators[index] = value; } + } + + /// <summary> + /// Removes the list item at the specified index. + /// </summary> + /// <param name="index">The zero-based index of the item to remove.</param> + public void RemoveAt(int index) + { + _navigators.RemoveAt(index); + } + + /// <summary> /// Resets the iterator. /// </summary> --- NEW FILE: SingletonXPathNodeIterator.cs --- #region using using System; using System.Xml.XPath; #endregion namespace Mvp.Xml.Common.XPath { /// <summary> /// <see cref="XPathNodeIterator"/> over a single node. /// </summary> public class SingletonXPathNodeIterator : XPathNodeIterator { private XPathNavigator navigator; private int position; #region ctors /// <summary> /// Creates new instance of SingletonXPathNodeIterator over /// given node. /// </summary> public SingletonXPathNodeIterator(XPathNavigator nav) { this.navigator = nav; } #endregion #region XPathNodeIterator impl /// <summary> /// See <see cref="XPathNodeIterator.Clone()"/> /// </summary> public override XPathNodeIterator Clone() { return new SingletonXPathNodeIterator(navigator.Clone()); } /// <summary> /// Always 1. See <see cref="XPathNodeIterator.Count"/> /// </summary> public override int Count { get { return 1; } } /// <summary> /// See <see cref="XPathNodeIterator.Current"/> /// </summary> public override XPathNavigator Current { get { return navigator; } } /// <summary> /// See <see cref="XPathNodeIterator.CurrentPosition"/> /// </summary> public override int CurrentPosition { get { return position; } } /// <summary> /// See <see cref="XPathNodeIterator.MoveNext()"/> /// </summary> public override bool MoveNext() { if (position == 0) { position = 1; return true; } return false; } #endregion } } --- NEW FILE: EmptyXPathNodeIterator.cs --- #region using using System; using System.Xml.XPath; #endregion namespace Mvp.Xml.Common.XPath { /// <summary> /// Empty <see cref="XPathNodeIterator"/>, used to represent empty /// node sequence. Implemented as a singleton. /// </summary> public class EmptyXPathNodeIterator : XPathNodeIterator { public static EmptyXPathNodeIterator Instance = new EmptyXPathNodeIterator(); /// <summary> /// This is a singleton, get an instance instead. /// </summary> private EmptyXPathNodeIterator() {} #region XPathNodeIterator implementation /// <summary> /// See <see cref="XPathNodeIterator.Clone()"/> /// </summary> public override XPathNodeIterator Clone() { return this; } /// <summary> /// Always 0. See <see cref="XPathNodeIterator.Count"/> /// </summary> public override int Count { get { return 0; } } /// <summary> /// Always null. See <see cref="XPathNodeIterator.Current"/> /// </summary> public override XPathNavigator Current { get { return null; } } /// <summary> /// Always 0. See <see cref="XPathNodeIterator.CurrentPosition"/> /// </summary> public override int CurrentPosition { get { return 0; } } /// <summary> /// Always false. See <see cref="XPathNodeIterator.MoveNext()"/> /// </summary> public override bool MoveNext() { return false; } #endregion } } |