Since writing the last post on this, I refined these methods a bit.
- Imports System.Runtime.CompilerServices
- Namespace Extensions
- ‘'’ <summary>
- ‘'’
- ‘'’ </summary>
- ‘'’ <remarks></remarks>
- Public Module IEnumerableExtensions
- ‘'’ <summary>
- ‘'’ Sees if the collection contains any of the parameters. If it finds one then it will return true else it will return false.
- ‘'’ </summary>
- ‘'’ <typeparam name="T">any object</typeparam>
- ‘'’ <param name="Collection">an IEnumerable of T</param>
- ‘'’ <param name="Parameters">an IEnumerable of T</param>
- ‘'’ <returns>True if at least one found, false if not found</returns>
- ‘'’ <remarks>This method equals the OR operator for all elements in Parameter collection. So if Collection contains parameter1 OR parameter2 OR parametern then it will return true.</remarks>
- <Extension()> _
- Public Function ContainsAny(Of T)(ByVal Collection As IEnumerable(Of T), ByVal Parameters As IEnumerable(Of T)) As Boolean
- Return Collection.ContainsAny(Parameters.ToArray)
- End Function
- ‘'’ <summary>
- ‘'’ Sees if the collection contains all of the parameters. if it finds all then it will return true else it will return false.
- ‘'’ </summary>
- ‘'’ <typeparam name="T">any object</typeparam>
- ‘'’ <param name="Collection">an IEnumerable of T</param>
- ‘'’ <param name="Parameters">an IEnumerable of T</param>
- ‘'’ <returns>True if all found, false if one not found</returns>
- ‘'’ <remarks>This method equals the AND operator for all elements in Parameter collection. So if Collection contains parameter1 AND parameter2 AND parametern then it will return true.</remarks>
- <Extension()> _
- Public Function ContainsAll(Of T)(ByVal Collection As IEnumerable(Of T), ByVal Parameters As IEnumerable(Of T)) As Boolean
- Return Collection.ContainsAll(Parameters.ToArray)
- End Function
- ‘'’ <summary>
- ‘'’ Sees if the collection contains any of the parameters. If it finds one then it will return true else it will return false.
- ‘'’ </summary>
- ‘'’ <typeparam name="T">any object</typeparam>
- ‘'’ <param name="Collection">an array of T</param>
- ‘'’ <param name="Parameters">an array of T</param>
- ‘'’ <returns>True if at least one found, false if not found</returns>
- ‘'’ <remarks>This method equals the OR operator for all elements in Parameter collection. So if Collection contains parameter1 OR parameter2 OR parametern then it will return true.</remarks>
- <Extension()> _
- Public Function ContainsAny(Of T)(ByVal Collection As IEnumerable(Of T), ByVal Parameters As T()) As Boolean
- For Each Parameter As T In Parameters
- If Collection.Contains(Parameter) Then
- Return True
- End If
- Next
- Return False
- End Function
- ‘'’ <summary>
- ‘'’ Sees if the collection contains all of the parameters. if it finds all then it will return true else it will return false.
- ‘'’ </summary>
- ‘'’ <typeparam name="T">any object</typeparam>
- ‘'’ <param name="Collection">an array of T</param>
- ‘'’ <param name="Parameters">an array of T</param>
- ‘'’ <returns>True if all found, false if one not found</returns>
- ‘'’ <remarks>This method equals the AND opearator for all elements in Parameter collection. So if Collection contains parameter1 AND parameter2 AND parametern then it will return true.</remarks>
- <Extension()> _
- Public Function ContainsAll(Of T)(ByVal Collection As IEnumerable(Of T), ByVal Parameters As T()) As Boolean
- For Each Parameter As T In Parameters
- If Not Collection.Contains(Parameter) Then
- Return False
- End If
- Next
- Return True
- End Function
- End Module
- End Namespace
This one now takes IEnumerable as the type (since ICollection inherits from IEnumerable it just broadens the scope) and it takes an IEnumerable or an array as parameters. Seems to do everything I want it to do right know.
And how do I know that? Because of 24 Unittests I wrote. I won’t post them here, but I have them on the wiki.





LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.