Make a copy of the old ZipLib
[mono.git] / mcs / class / System.Configuration / System.Configuration / CommaDelimitedStringCollection.cs
1 //
2 // System.Configuration.CommaDelimitedStringCollection.cs
3 //
4 // Authors:
5 //      Chris Toshok (toshok@ximian.com)
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining
8 // a copy of this software and associated documentation files (the
9 // "Software"), to deal in the Software without restriction, including
10 // without limitation the rights to use, copy, modify, merge, publish,
11 // distribute, sublicense, and/or sell copies of the Software, and to
12 // permit persons to whom the Software is furnished to do so, subject to
13 // the following conditions:
14 // 
15 // The above copyright notice and this permission notice shall be
16 // included in all copies or substantial portions of the Software.
17 // 
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 //
26 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
27 //
28
29 #if NET_2_0
30 using System;
31 using System.Collections.Specialized;
32
33 namespace System.Configuration {
34
35         /* i really hate all these "new"s... maybe
36          * StringCollection marks these methods as virtual in
37          * 2.0? */
38         public sealed class CommaDelimitedStringCollection : StringCollection {
39
40                 bool modified;
41                 bool readOnly;
42
43                 public bool IsModified {
44                         get {
45                                 return modified;
46                         }
47                 }
48
49                 public new bool IsReadOnly {
50                         get {
51                                 return readOnly;
52                         }
53                 }
54
55                 public new string this [int index] {
56                         get {
57                                 return base [index];
58                         }
59                         set {
60                                 if (readOnly)
61                                         throw new ConfigurationErrorsException ("The configuration is read only");
62
63                                 base [index] = value;
64                                 modified = true;
65                         }
66                 }
67
68                 public new void Add (string value)
69                 {
70                         if (readOnly)
71                                 throw new ConfigurationErrorsException ("The configuration is read only");
72
73                         base.Add (value);
74                         modified = true;
75                 }
76
77                 public new void AddRange (string[] range)
78                 {
79                         if (readOnly)
80                                 throw new ConfigurationErrorsException ("The configuration is read only");
81
82                         base.AddRange (range);
83                         modified = true;
84                 }
85
86                 public new void Clear ()
87                 {
88                         if (readOnly)
89                                 throw new ConfigurationErrorsException ("The configuration is read only");
90
91                         base.Clear ();
92                         modified = true;
93                 }
94
95                 public CommaDelimitedStringCollection Clone ()
96                 {
97                         CommaDelimitedStringCollection col = new CommaDelimitedStringCollection();
98                         string[] contents = new string[this.Count];
99                         CopyTo (contents, 0);
100                         
101                         col.AddRange (contents);
102
103                         return col;
104                 }
105
106                 public new void Insert (int index, string value)
107                 {
108                         if (readOnly)
109                                 throw new ConfigurationErrorsException ("The configuration is read only");
110
111                         base.Insert (index, value);
112                         modified = true;
113                 }
114
115                 public new void Remove (string value)
116                 {
117                         if (readOnly)
118                                 throw new ConfigurationErrorsException ("The configuration is read only");
119
120                         base.Remove (value);
121                         modified = true;
122                 }
123
124                 public void SetReadOnly ()
125                 {
126                         readOnly = true;
127                 }
128
129                 public new string ToString ()
130                 {
131                         if (this.Count == 0)
132                                 return null;
133
134                         string[] contents = new string[this.Count];
135
136                         CopyTo (contents, 0);
137
138                         return String.Join (",", contents);
139                 }
140         }
141
142 }
143
144 #endif