using System.Collections; using System.Collections.Generic; using ICD.Common.Properties; using ICD.Common.Utils.Extensions; namespace ICD.Common.Utils.Email { /// /// Stores addresses/paths and provides them in a ; delimited string. /// public sealed class EmailStringCollection : ICollection { private const char DELIMITER = ';'; private readonly List m_Items; /// /// Gets the number of items. /// public int Count { get { return m_Items.Count; } } public bool IsReadOnly { get { return false; } } /// /// Constructor. /// public EmailStringCollection() { m_Items = new List(); } #region Methods /// /// Adds the item to the collection. /// /// /// [PublicAPI] public bool Add(string item) { if (m_Items.Contains(item)) return false; m_Items.Add(item); return true; } /// /// Removes the item from the collection. /// /// /// [PublicAPI] public bool Remove(string item) { if (!m_Items.Contains(item)) return false; m_Items.Remove(item); return true; } /// /// Clears all items. /// public void Clear() { m_Items.Clear(); } /// /// Returns true if the collection contains the item. /// /// /// [PublicAPI] public bool Contains(string item) { return m_Items.Contains(item); } /// /// Gets the items as a ; delimited string. /// /// public override string ToString() { return string.Join(DELIMITER.ToString(), m_Items.ToArray()); } #endregion #region Collection void ICollection.Add(string item) { Add(item); } /// /// Adds multiple email addresses, seperated by ; /// /// public void AddMany(string items) { items = items.RemoveWhitespace(); string [] splitItems = items.Split(DELIMITER); foreach (string item in splitItems) Add(item); } public void CopyTo(string[] array, int arrayIndex) { m_Items.CopyTo(array, arrayIndex); } #endregion #region Enumerable public IEnumerator GetEnumerator() { return m_Items.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return GetEnumerator(); } #endregion } }