1 //------------------------------------------------------------------------------
2 // <copyright file="ConnectionInterfaceCollection.cs" company="Microsoft">
3 //     Copyright (c) Microsoft Corporation.  All rights reserved.
4 // </copyright>
5 //------------------------------------------------------------------------------
6 
7 namespace System.Web.UI.WebControls.WebParts {
8 
9     using System;
10     using System.Collections;
11     using System.ComponentModel;
12 
13     public sealed class ConnectionInterfaceCollection : ReadOnlyCollectionBase {
14 
15         public static readonly ConnectionInterfaceCollection Empty = new ConnectionInterfaceCollection();
16 
ConnectionInterfaceCollection()17         public ConnectionInterfaceCollection() {
18         }
19 
ConnectionInterfaceCollection(ICollection connectionInterfaces)20         public ConnectionInterfaceCollection(ICollection connectionInterfaces) {
21             Initialize(null, connectionInterfaces);
22         }
23 
ConnectionInterfaceCollection(ConnectionInterfaceCollection existingConnectionInterfaces, ICollection connectionInterfaces)24         public ConnectionInterfaceCollection(ConnectionInterfaceCollection existingConnectionInterfaces,
25                                              ICollection connectionInterfaces) {
26             Initialize(existingConnectionInterfaces, connectionInterfaces);
27         }
28 
Initialize(ConnectionInterfaceCollection existingConnectionInterfaces, ICollection connectionInterfaces)29         private void Initialize(ConnectionInterfaceCollection existingConnectionInterfaces, ICollection connectionInterfaces) {
30             if (existingConnectionInterfaces != null) {
31                 foreach (Type existingConnectionInterface in existingConnectionInterfaces) {
32                     // Don't need to check arg, since we know it is valid since it came
33                     // from a ConnectionInterfaceCollection.
34                     InnerList.Add(existingConnectionInterface);
35                 }
36             }
37 
38             if (connectionInterfaces != null) {
39                 foreach (object obj in connectionInterfaces) {
40                     if (obj == null) {
41                         throw new ArgumentException(SR.GetString(SR.Collection_CantAddNull), "connectionInterfaces");
42                     }
43                     if (!(obj is Type)) {
44                         throw new ArgumentException(SR.GetString(SR.Collection_InvalidType, "Type"), "connectionInterfaces");
45                     }
46                     InnerList.Add(obj);
47                 }
48             }
49         }
50 
Contains(Type value)51         public bool Contains(Type value) {
52             return InnerList.Contains(value);
53         }
54 
IndexOf(Type value)55         public int IndexOf(Type value) {
56             return InnerList.IndexOf(value);
57         }
58 
59         public Type this[int index] {
60             get {
61                 return (Type)InnerList[index];
62             }
63         }
64 
CopyTo(Type[] array, int index)65         public void CopyTo(Type[] array, int index) {
66             InnerList.CopyTo(array, index);
67         }
68     }
69 }
70 
71 
72