/// <summary> /// Gets the index of an item in the collection /// </summary> /// <param name="item">Item to get the index of</param> /// <returns>Index of the item, or -1 if the item doesn't exist</returns> public int IndexOf(FileHistoryItem item) { int returnValue = -1; for (int index = 0; index < _files.Count; index++) { if ((_files[index] != null) && (_files[index].Equals(item))) { returnValue = index; break; } } return(returnValue); }
/// <summary> /// Adds an item to the collection /// </summary> /// <param name="filePath">Item to add</param> public void AddItem(string filePath) { FileHistoryItem item = new FileHistoryItem(filePath); if (!Exists(item)) { if (_files.Count >= MaxNumberOfItems) { _files.RemoveAt(0); } _files.Add(item); OnSettingsChanged(); } }
/// <summary> /// Checks if this instance is equal to another instance /// </summary> /// <param name="obj">Instance to compare to</param> /// <returns>-1 if less than, 0 if equal, 1 if greater than</returns> public override bool Equals(object obj) { if ((obj == null) || (obj is System.DBNull)) { return(false); } FileHistoryItem item = (FileHistoryItem)obj; if (string.Compare(item.FilePath, _filePath) == 0) { return(true); } else { return(false); } }
/// <summary> /// Checks if an item exists in the collection /// </summary> /// <param name="item">Item to check for</param> /// <returns>True if the item exists</returns> public bool Exists(FileHistoryItem item) { return(IndexOf(item) > -1); }
/// <summary> /// Removes the given item from the collection /// </summary> /// <param name="item">Item to remove</param> public void Remove(FileHistoryItem item) { _files.Remove(item); OnSettingsChanged(); }