/// <summary> /// Copy into an array contents of the btree. /// </summary> /// <param name="DestArray">Destination array that will contain the items.</param> /// <param name="StartIndex">Start index to start copying into</param> /// <remarks> /// On error, throws following Exceptions: /// </remarks> /// <remarks> /// ArgumentNullException - array is a null reference (Nothing in Visual Basic). /// </remarks> /// <remarks> /// ArgumentOutOfRangeException - arrayIndex is less than zero. /// </remarks> /// <remarks> /// ArgumentException - array is multidimensional. /// -or- /// </remarks> /// <remarks> /// arrayIndex is equal to or greater than the length of array. /// -or- /// </remarks> /// <remarks> /// arrayIndex is equal to or greater than the length of array. /// -or- /// </remarks> /// <remarks> /// The number of elements in the source Hashtable is greater than the available space from arrayIndex to the end of the destination array. /// </remarks> public void CopyTo(Array DestArray, int StartIndex) { if (DestArray == null) { throw new ArgumentNullException(BTree.GetStringResource("DestArray"), BTree.GetStringResource("DestArrayIsNull")); } if (StartIndex < 0) #if DEVICE { throw new ArgumentOutOfRangeException(BTree.GetStringResource("DestArray") + " " + StartIndex.ToString() + " " + BTree.GetStringResource("StartIndexIsNegative")); } #else { throw new ArgumentOutOfRangeException(BTree.GetStringResource("DestArray"), (object)StartIndex, BTree.GetStringResource("StartIndexIsNegative")); } #endif if (DestArray.Rank > 1) { throw new ArgumentException(BTree.GetStringResource("DestArrayIsMulti")); } if (StartIndex >= DestArray.Length) { throw new ArgumentException(BTree.GetStringResource("StartIndexIsGreaterThanLength")); } if (this.Count > DestArray.Length - StartIndex) { throw new ArgumentException(BTree.GetStringResource("BTreeHasMoreElems")); } foreach (object o in this) { DestArray.SetValue(o, StartIndex); StartIndex++; } }
/// <summary> /// Compare object x's key with object y's key.<br/> /// Returns:<br/> /// < 0 if x.Key is < y.Key<br/> /// > 0 if x.Key > y.Key<br/> /// == 0 if x.Key == y.Key /// </summary> /// <param name="x">1st object whose key is to be compared</param> /// <param name="y">2nd object whose key is to be compared</param> /// <returns></returns> public int Compare(object x, object y) { try { if (IsComparingObject) { int xHash = x.GetHashCode(); int yHash = y.GetHashCode(); return(xHash.CompareTo(yHash)); } object xKey = x; if (x is DictionaryEntry) { xKey = ((DictionaryEntry)x).Key; } object yKey = y; if (y is DictionaryEntry) { yKey = ((DictionaryEntry)y).Key; } return(System.Collections.Comparer.Default.Compare(xKey, yKey)); } catch (Exception e) { if (!(x is ValueType || IsComparingObject)) { IsComparingObject = true; if (x == null) { throw new ArgumentNullException("x"); } if (y == null) { throw new ArgumentNullException("y"); } try { int xHash = x.GetHashCode(); int yHash = y.GetHashCode(); return(xHash.CompareTo(yHash)); } catch { } } throw new InvalidOperationException(BTree.GetStringResource("NoComparerError"), e); } }
/// <summary> /// Compare string value of object x's key with object y's key<br/> /// Returns:<br/> /// < 0 if x.Key is < y.Key<br/> /// > 0 if x.Key > y.Key<br/> /// == 0 if x.Key == y.Key /// </summary> /// <param name="x">1st object whose key is to be compared</param> /// <param name="y">2nd object whose key is to be compared</param> /// <returns></returns> public int Compare(object x, object y) { try { object xKey = x; if (x is DictionaryEntry) { xKey = ((DictionaryEntry)x).Key; } object yKey = y; if (y is DictionaryEntry) { yKey = ((DictionaryEntry)y).Key; } return(xKey.ToString().CompareTo(yKey.ToString())); } catch (Exception e) { throw new InvalidOperationException(BTree.GetStringResource("NoComparerError"), e); } }