Minor orbis fix in System.Net
[mono.git] / mcs / nunit24 / ClientUtilities / util / ProjectConfigCollection.cs
1 // ****************************************************************\r
2 // This is free software licensed under the NUnit license. You\r
3 // may obtain a copy of the license as well as information regarding\r
4 // copyright ownership at http://nunit.org/?p=license&r=2.4.\r
5 // ****************************************************************\r
6 \r
7 using System;\r
8 using System.Collections;\r
9 \r
10 namespace NUnit.Util\r
11 {\r
12         /// <summary>\r
13         /// Summary description for ProjectConfigCollection.\r
14         /// </summary>\r
15         public class ProjectConfigCollection : CollectionBase\r
16         {\r
17                 protected NUnitProject project;\r
18 \r
19                 public ProjectConfigCollection( NUnitProject project ) \r
20                 { \r
21                         this.project = project;\r
22                 }\r
23 \r
24                 #region Properties\r
25                 public ProjectConfig this[int index]\r
26                 {\r
27                         get { return (ProjectConfig)InnerList[index]; }\r
28                 }\r
29 \r
30                 public ProjectConfig this[string name]\r
31                 {\r
32                         get \r
33                         { \r
34                                 int index = IndexOf( name );\r
35                                 return index >= 0 ? (ProjectConfig)InnerList[index]: null;\r
36                         }\r
37                 }\r
38                 #endregion\r
39 \r
40                 #region Methods\r
41                 public void Add( ProjectConfig config )\r
42                 {\r
43                         List.Add( config );\r
44                         config.Project = this.project;\r
45                         config.Changed += new EventHandler(config_Changed);\r
46                 }\r
47 \r
48                 public void Add( string name )\r
49                 {\r
50                         Add( new ProjectConfig( name ) );\r
51                 }\r
52 \r
53                 public void Remove( string name )\r
54                 {\r
55                         int index = IndexOf( name );\r
56                         if ( index >= 0 )\r
57                         {\r
58                                 RemoveAt( index );\r
59                         }\r
60                 }\r
61 \r
62                 private int IndexOf( string name )\r
63                 {\r
64                         for( int index = 0; index < InnerList.Count; index++ )\r
65                         {\r
66                                 ProjectConfig config = (ProjectConfig)InnerList[index];\r
67                                 if( config.Name == name )\r
68                                         return index;\r
69                         }\r
70 \r
71                         return -1;\r
72                 }\r
73 \r
74                 public bool Contains( ProjectConfig config )\r
75                 {\r
76                         return InnerList.Contains( config );\r
77                 }\r
78 \r
79                 public bool Contains( string name )\r
80                 {\r
81                         return IndexOf( name ) >= 0;\r
82                 }\r
83 \r
84                 protected override void OnRemoveComplete( int index, object obj )\r
85                 {\r
86                         ProjectConfig config = obj as ProjectConfig;\r
87                         this.project.OnProjectChange( ProjectChangeType.RemoveConfig, config.Name );\r
88                 }\r
89 \r
90                 protected override void OnInsertComplete( int index, object obj )\r
91                 {\r
92                         ProjectConfig config = obj as ProjectConfig;\r
93                         project.OnProjectChange( ProjectChangeType.AddConfig, config.Name );\r
94                 }\r
95 \r
96                 private void config_Changed(object sender, EventArgs e)\r
97                 {\r
98                         ProjectConfig config = sender as ProjectConfig;\r
99                         project.OnProjectChange( ProjectChangeType.UpdateConfig, config.Name );\r
100                 }\r
101                 #endregion\r
102         }\r
103 }\r