2002-08-12 Tim Coleman <tim@timcoleman.com>
[mono.git] / mcs / class / System.Web.Services / System.Web.Services.Description / BindingCollection.cs
1 // \r
2 // System.Web.Services.Description.BindingCollection.cs\r
3 //\r
4 // Author:\r
5 //   Tim Coleman (tim@timcoleman.com)\r
6 //\r
7 // Copyright (C) Tim Coleman, 2002\r
8 //\r
9 \r
10 namespace System.Web.Services.Description {\r
11         public sealed class BindingCollection : ServiceDescriptionBaseCollection {\r
12                 \r
13                 #region Fields\r
14 \r
15                 ServiceDescription serviceDescription;\r
16 \r
17                 #endregion // Fields\r
18 \r
19                 #region Constructors\r
20         \r
21                 internal BindingCollection (ServiceDescription serviceDescription) \r
22                 {\r
23                         this.serviceDescription = serviceDescription;\r
24                 }\r
25 \r
26                 #endregion // Constructors\r
27 \r
28                 #region Properties\r
29 \r
30                 public Binding this [int index] {\r
31                         get { \r
32                                 if (index < 0 || index > Count)\r
33                                         throw new ArgumentOutOfRangeException ();\r
34                                 return (Binding) List[index]; \r
35                         }\r
36                         set {\r
37                                 Table.Remove (GetKey (List[index]));\r
38                                 Table [GetKey (value)] = value;\r
39                                 List [index] = value;\r
40                         }\r
41                 }\r
42 \r
43                 public Binding this [string name] {\r
44                         get { return this[IndexOf ((Binding) Table[name])]; }\r
45                 }\r
46 \r
47                 #endregion // Properties\r
48 \r
49                 #region Methods\r
50 \r
51                 public int Add (Binding binding) \r
52                 {\r
53                         Insert (Count, binding);\r
54                         return (Count - 1);\r
55                 }\r
56 \r
57                 public bool Contains (Binding binding)\r
58                 {\r
59                         return List.Contains (binding);\r
60                 }\r
61 \r
62                 public void CopyTo (Binding[] array, int index) \r
63                 {\r
64                         List.CopyTo (array, index);\r
65                 }\r
66 \r
67                 protected override string GetKey (object value) \r
68                 {\r
69                         if (!(value is Binding))\r
70                                 throw new InvalidCastException ();\r
71                         return ((Binding) value).Name;\r
72                 }\r
73 \r
74                 public int IndexOf (Binding binding)\r
75                 {\r
76                         return List.IndexOf (binding);\r
77                 }\r
78 \r
79                 public void Insert (int index, Binding binding)\r
80                 {\r
81                         SetParent (binding, serviceDescription);\r
82                         Table [GetKey (binding)] = binding;\r
83                         List.Insert (index, binding);\r
84                 }\r
85         \r
86                 public void Remove (Binding binding)\r
87                 {\r
88                         Table.Remove (GetKey (binding));\r
89                         List.Remove (binding);\r
90                 }\r
91                         \r
92                 protected override void SetParent (object value, object parent)\r
93                 {\r
94                         ((Binding) value).SetParent ((ServiceDescription) parent);\r
95                 }\r
96                         \r
97                 #endregion // Methods\r
98         }\r
99 }\r