PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/PrismLibrary/Desktop/Prism/CollectionExtensions.cs

#
C# | 48 lines | 18 code | 3 blank | 27 comment | 4 complexity | 7f69cb4670c9f23d04eacfe9d82cb115 MD5 | raw file
  1. //===================================================================================
  2. // Microsoft patterns & practices
  3. // Composite Application Guidance for Windows Presentation Foundation and Silverlight
  4. //===================================================================================
  5. // Copyright (c) Microsoft Corporation. All rights reserved.
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
  7. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
  8. // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  9. // FITNESS FOR A PARTICULAR PURPOSE.
  10. //===================================================================================
  11. // The example companies, organizations, products, domain names,
  12. // e-mail addresses, logos, people, places, and events depicted
  13. // herein are fictitious. No association with any real company,
  14. // organization, product, domain name, email address, logo, person,
  15. // places, or events is intended or should be inferred.
  16. //===================================================================================
  17. using System.Collections.Generic;
  18. using System.Collections.ObjectModel;
  19. namespace Microsoft.Practices.Prism
  20. {
  21. /// <summary>
  22. /// Class that provides extension methods to Collection
  23. /// </summary>
  24. public static class CollectionExtensions
  25. {
  26. /// <summary>
  27. /// Add a range of items to a collection.
  28. /// </summary>
  29. /// <typeparam name="T">Type of objects within the collection.</typeparam>
  30. /// <param name="collection">The collection to add items to.</param>
  31. /// <param name="items">The items to add to the collection.</param>
  32. /// <returns>The collection.</returns>
  33. /// <exception cref="System.ArgumentNullException">An <see cref="System.ArgumentNullException"/> is thrown if <paramref name="collection"/> or <paramref name="items"/> is <see langword="null"/>.</exception>
  34. public static Collection<T> AddRange<T>(this Collection<T> collection, IEnumerable<T> items)
  35. {
  36. if (collection == null) throw new System.ArgumentNullException("collection");
  37. if (items == null) throw new System.ArgumentNullException("items");
  38. foreach (var each in items)
  39. {
  40. collection.Add(each);
  41. }
  42. return collection;
  43. }
  44. }
  45. }