using System; using System.Collections.Generic; using System.Net; using System.Runtime.CompilerServices; namespace Swan.Net { /// /// Provides extension methods for instances and collections of . /// public static class IPAddressRangeExtensions { /// /// Determines whether any element of a sequence of instances /// contains the given . /// /// The IEnumerable<IPAddressRange> interface /// on which this method is called. /// The to look for. /// if any of the ranges in /// contains ; otherwise, . /// is . public static bool AnyContains(this IEnumerable @this, IPAddress address) { if (@this == null) throw new ArgumentNullException(nameof(@this)); foreach (var range in @this) { if (range.Contains(address)) return true; } return false; } /// /// Determines whether no element of a sequence of instances /// contains the given . /// /// The IEnumerable<IPAddressRange> interface /// on which this method is called. /// The to look for. /// if none of the ranges in /// contains ; otherwise, . /// is . [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool NoneContains(this IEnumerable @this, IPAddress address) => !AnyContains(@this, address); } }