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