Пример #1
0
 /// <summary>
 /// Adds a network to the collection.
 /// </summary>
 /// <param name="source">The <see cref="Collection{IPObject}"/>.</param>
 /// <param name="item">Item to add.</param>
 /// <param name="itemsAreNetworks">If <c>true</c> the values are treated as subnets.
 /// If <b>false</b> items are addresses.</param>
 public static void AddItem(this Collection <IPObject> source, IPObject item, bool itemsAreNetworks = true)
 {
     if (!source.ContainsAddress(item) || !itemsAreNetworks)
     {
         source.Add(item);
     }
 }
Пример #2
0
 /// <summary>
 /// Adds a network to the collection.
 /// </summary>
 /// <param name="source">The <see cref="Collection{IPObject}"/>.</param>
 /// <param name="item">Item to add.</param>
 public static void AddItem(this Collection <IPObject> source, IPObject item)
 {
     if (!source.ContainsAddress(item))
     {
         source.Add(item);
     }
 }
Пример #3
0
 /// <inheritdoc/>
 public override bool Contains(IPObject address)
 {
     if (address is IPHost addressObj && addressObj.HasAddress)
     {
         foreach (IPAddress addr in addressObj.GetAddresses())
         {
             if (Contains(addr))
             {
                 return(true);
             }
         }
     }
Пример #4
0
        /// <summary>
        /// Returns true if the collection contains an item with the ip address,
        /// or the ip address falls within any of the collection's network ranges.
        /// </summary>
        /// <param name="source">The <see cref="Collection{IPObject}"/>.</param>
        /// <param name="item">The item to look for.</param>
        /// <returns>True if the collection contains the item.</returns>
        public static bool ContainsAddress(this Collection <IPObject> source, IPObject item)
        {
            if (source.Count == 0)
            {
                return(false);
            }

            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            foreach (var i in source)
            {
                if (i.Contains(item))
                {
                    return(true);
                }
            }

            return(false);
        }