In .:
[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 { return modified; }
45                 }
46
47                 public new bool IsReadOnly {
48                         get { return readOnly; }
49                 }
50
51                 public new string this [int index] {
52                         get { return base [index]; }
53                         set {
54                                 if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
55
56                                 base [index] = value;
57                                 modified = true;
58                         }
59                 }
60
61                 public new void Add (string value)
62                 {
63                         if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
64
65                         base.Add (value);
66                         modified = true;
67                 }
68
69                 public new void AddRange (string[] range)
70                 {
71                         if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
72
73                         base.AddRange (range);
74                         modified = true;
75                 }
76
77                 public new void Clear ()
78                 {
79                         if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
80
81                         base.Clear ();
82                         modified = true;
83                 }
84
85                 public CommaDelimitedStringCollection Clone ()
86                 {
87                         CommaDelimitedStringCollection col = new CommaDelimitedStringCollection();
88                         string[] contents = new string[this.Count];
89                         CopyTo (contents, 0);
90                         
91                         col.AddRange (contents);
92
93                         return col;
94                 }
95
96                 public new void Insert (int index, string value)
97                 {
98                         if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
99
100                         base.Insert (index, value);
101                         modified = true;
102                 }
103
104                 public new void Remove (string value)
105                 {
106                         if (readOnly) throw new ConfigurationErrorsException ("The configuration is read only");
107
108                         base.Remove (value);
109                         modified = true;
110                 }
111
112                 public void SetReadOnly ()
113                 {
114                         readOnly = true;
115                 }
116
117                 public override string ToString ()
118                 {
119                         if (this.Count == 0)
120                                 return null;
121
122                         string[] contents = new string[this.Count];
123
124                         CopyTo (contents, 0);
125
126                         return String.Join (",", contents);
127                 }
128         }
129
130 }
131
132 #endif