PageRenderTime 21ms CodeModel.GetById 11ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/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//===================================================================================
17using System.Collections.Generic;
18using System.Collections.ObjectModel;
19
20namespace Microsoft.Practices.Prism
21{
22    /// <summary>
23    /// Class that provides extension methods to Collection
24    /// </summary>
25    public static class CollectionExtensions
26    {
27        /// <summary>
28        /// Add a range of items to a collection.
29        /// </summary>
30        /// <typeparam name="T">Type of objects within the collection.</typeparam>
31        /// <param name="collection">The collection to add items to.</param>
32        /// <param name="items">The items to add to the collection.</param>
33        /// <returns>The collection.</returns>
34        /// <exception cref="System.ArgumentNullException">An <see cref="System.ArgumentNullException"/> is thrown if <paramref name="collection"/> or <paramref name="items"/> is <see langword="null"/>.</exception>
35        public static Collection<T> AddRange<T>(this Collection<T> collection, IEnumerable<T> items)
36        {
37            if (collection == null) throw new System.ArgumentNullException("collection");
38            if (items == null) throw new System.ArgumentNullException("items");
39
40            foreach (var each in items)
41            {
42                collection.Add(each);
43            }
44
45            return collection;
46        }
47    }
48}