Determines whether the collection contains all the elements in the specified collection. : IEnumerable « Collections Data Structure « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » Collections Data Structure » IEnumerableScreenshots 
Determines whether the collection contains all the elements in the specified collection.
    

/*
 * Copyright  2002-2005 the original author or authors.
 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 
 *      http://www.apache.org/licenses/LICENSE-2.0
 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;

namespace Spring.Util.Generic
{
  /// <summary>
  /// Miscellaneous generic collection utility methods.
  /// </summary>
  /// <remarks>
  /// Mainly for internal use within the framework.
  /// </remarks>
  /// <author>Mark Pollack (.NET)</author>
  public sealed class CollectionUtils
  {
    /// <summary>
    /// Determines whether the collection contains all the elements in the specified collection.
    /// </summary>
    /// <param name="targetCollection">The collection to check.</param>
    /// <param name="sourceCollection">Collection whose elements would be checked for containment.</param>
    /// <returns>true if the target collection contains all the elements of the specified collection.</returns>
    public static bool ContainsAll<T>(ICollection<T> targetCollection, ICollection<T> sourceCollection)
    {
      if (targetCollection == null || sourceCollection == null)
      {
        throw new ArgumentNullException("Collection cannot be null.");
      }
      if sourceCollection.Count == && targetCollection.Count > )
        return true;

      IEnumerator sourceCollectionEnumerator = sourceCollection.GetEnumerator();

      bool contains = false;

      MethodInfo method;
      method = targetCollection.GetType().GetMethod("containsAll", BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);

      if (method != null)
        contains = (boolmethod.Invoke(targetCollection, new Object[] {sourceCollection});
      else
      {
        method = targetCollection.GetType().GetMethod("Contains", BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public);
        if (method == null)
        {
          throw new InvalidOperationException("Target collection does not implment a Contains() or ContainsAll() method.");
        }
        while (sourceCollectionEnumerator.MoveNext())
        {
          if ((contains = (boolmethod.Invoke(targetCollection, new Object[] {sourceCollectionEnumerator.Current})) == false)
            break;
        }
      }
      return contains;
    }
    }
}

   
    
    
    
  
Related examples in the same category
1.Determines whether the specified collection is null or empty.
2.Determines whether the collection contains the specified element
3.Aggregate IEnumerable
4.Convert IEnumerable To DataTable
5.Convert IEnumerable by Func
6.Split IEnumerable
7.Shuffle IEnumerable
8.For each IEnumerable
9.Sleep before yield each element in IEnumerable
10.Add WhereIf to IEnumerable
11.Add OrderBy to IEnumerable
12.Add Repeat extension to IEnumerable
13.Yield element in IEnumerable until Predicate
14.IEnumerable extension for get second and third element
15.Simple function to determine if an item is an IEnumerable
16.Object class extension for IEnumerable, IComparable and where
17.Output DataTable and IEnumerable to console
18.Convert IEnumerable to String
19.Convert XmlNodeList to IEnumerable
20.Returns the first element contained in both, source and candidates.
21.Given a range (start,end) and a number of steps, will yield that a number for each step
22.Compares two sequences.
23.Empty Enumerable/Enumerator
24.CharEnumerator supports iterating over a String and reading its individual characters.
25.IEnumerable interface exposes the enumerator, which supports a simple iteration over a non-generic collection.
26.IEnumerator interface supports a simple iteration over a nongeneric collection.
27.Convert IEnumerable to ObservableCollection
28.IEnumerable To Comma String
29.Do all for IEnumerable and Action
30.Convert IEnumerable to IEnumerable
31.Filter IEnumerable with Predicate
32.Join IEnumerable
33.Mode value for IEnumerable
34.Build Statistics function on to IEnumerable
35.Compare two IEnumerable
36.Convert IEnumerable to HashSet
37.Concatenate IEnumerable to String
38.Singleton IEnumerable
39.Convert IEnumerable To ReadOnlyCollection
40.Performs the specified action on each element of the IEnumerable
41.Creates a list by applying a delegate to pairs of items in the IEnumerable
42.Returns true if there are enough items in the IEnumerable
43.Returns true if there are no more than a set number of items in the IEnumerable
44.Groups items into same size lots.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.