using System.Collections; using System.Linq; using NETCONLib; namespace Netch.Models.WinFW { /// /// A collection that stores 'NetworkConnection' objects. /// public class NetworkConnectionCollection : CollectionBase { /// /// Initializes a new instance of 'NetworkConnectionCollection'. /// public NetworkConnectionCollection() { NetSharingManager icsMgr = new NetSharingManagerClass(); foreach (var icsConn in icsMgr.EnumEveryConnection.Cast()) { Add(new NetworkConnection(icsConn)); } } /// /// Represents the 'NetworkConnection' item at the specified index position. /// /// /// The zero-based index of the entry to locate in the collection. /// /// /// The entry at the specified index of the collection. /// public NetworkConnection this[int intIndex] { get => (NetworkConnection) List[intIndex]; set => List[intIndex] = value; } /// /// Adds a 'NetworkConnection' item with the specified value to the 'NetworkConnectionCollection' /// /// /// The 'NetworkConnection' to add. /// /// /// The index at which the new element was inserted. /// public int Add(NetworkConnection conValue) { return List.Add(conValue); } /// /// Copies the elements of an array at the end of this instance of 'NetworkConnectionCollection'. /// /// /// An array of 'NetworkConnection' objects to add to the collection. /// public void AddRange(NetworkConnection[] conValue) { checked { foreach (var t in conValue) Add(t); } } /// /// Adds the contents of another 'NetworkConnectionCollection' at the end of this instance. /// /// /// A 'NetworkConnectionCollection' containing the objects to add to the collection. /// public void AddRange(NetworkConnectionCollection conValue) { checked { for (var intCounter = 0; intCounter < conValue.Count; intCounter++) Add(conValue[intCounter]); } } /// /// Gets a value indicating whether the 'NetworkConnectionCollection' contains the specified value. /// /// /// The item to locate. /// /// /// True if the item exists in the collection; false otherwise. /// public bool Contains(NetworkConnection conValue) { return List.Contains(conValue); } /// /// Copies the 'NetworkConnectionCollection' values to a one-dimensional System.Array /// instance starting at the specified array index. /// /// /// The one-dimensional System.Array that represents the copy destination. /// /// /// The index in the array where copying begins. /// public void CopyTo(NetworkConnection[] conArray, int intIndex) { List.CopyTo(conArray, intIndex); } /// /// Returns the index of a 'NetworkConnection' object in the collection. /// /// /// The 'NetworkConnection' object whose index will be retrieved. /// /// /// If found, the index of the value; otherwise, -1. /// public int IndexOf(NetworkConnection conValue) { return List.IndexOf(conValue); } /// /// Inserts an existing 'NetworkConnection' into the collection at the specified index. /// /// /// The zero-based index where the new item should be inserted. /// /// /// The item to insert. /// public void Insert(int intIndex, NetworkConnection conValue) { List.Insert(intIndex, conValue); } /// /// Returns an enumerator that can be used to iterate through /// the 'NetworkConnectionCollection'. /// public new ConnectionEnumerator GetEnumerator() { return new ConnectionEnumerator(this); } /// /// Removes a specific item from the 'NetworkConnectionCollection'. /// /// /// The item to remove from the 'NetworkConnectionCollection'. /// public void Remove(NetworkConnection conValue) { List.Remove(conValue); } /// /// A strongly typed enumerator for 'NetworkConnectionCollection' /// public class ConnectionEnumerator : IEnumerator { private readonly IEnumerator iEnBase; private readonly IEnumerable iEnLocal; /// /// Enumerator constructor /// public ConnectionEnumerator(NetworkConnectionCollection conMappings) { iEnLocal = conMappings; iEnBase = iEnLocal.GetEnumerator(); } /// /// Gets the current element from the collection /// public object Current => iEnBase.Current; /// /// Advances the enumerator to the next element of the collection /// public bool MoveNext() { return iEnBase.MoveNext(); } /// /// Sets the enumerator to the first element in the collection /// public void Reset() { iEnBase.Reset(); } } } }