* BuildEngine.cs (BuildProjectFile): Use AddProperty method to specify
[mono.git] / mcs / class / System.XML / System.Xml.Serialization.Advanced / SchemaImporterExtensionCollection.cs
1 // 
2 // System.Xml.Serialization.SchemaImporterExtensionCollection.cs 
3 //
4 // Author:
5 //   Lluis Sanchez Gual (lluis@novell.com)
6 //   Atsushi Enomoto (atsushi@ximian.com)
7 //
8 // Copyright (C) Novell, Inc., 2004, 2006
9 //
10
11 //
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
19 // 
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
22 // 
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 //
31
32 #if NET_2_0
33
34 using System;
35 using System.Collections;
36 using System.Collections.Generic;
37
38 namespace System.Xml.Serialization.Advanced
39 {
40         public class SchemaImporterExtensionCollection : CollectionBase
41         {
42                 Dictionary<string,SchemaImporterExtension> named_items =
43                         new Dictionary<string,SchemaImporterExtension> ();
44
45                 public SchemaImporterExtensionCollection ()
46                 {
47                 }
48
49                 public int Add (SchemaImporterExtension extension)
50                 {
51                         if (extension == null)
52                                 throw new ArgumentNullException ("extension");
53                         return List.Add (extension);
54                 }
55
56                 public int Add (string key, Type type)
57                 {
58                         if (key == null)
59                                 throw new ArgumentNullException ("key");
60                         if (type == null)
61                                 throw new ArgumentNullException ("type");
62                         if (!type.IsSubclassOf (typeof (SchemaImporterExtension)))
63                                 throw new ArgumentException ("The type argument must be subclass of SchemaImporterExtension.");
64
65                         SchemaImporterExtension e = (SchemaImporterExtension) Activator.CreateInstance (type);
66                         if (named_items.ContainsKey (key))
67                                 throw new InvalidOperationException (String.Format ("A SchemaImporterExtension keyed by '{0}' already exists.", key));
68                         int ret = Add (e);
69                         named_items.Add (key, e);
70                         return ret;
71                 }
72         
73                 public new void Clear ()
74                 {
75                         named_items.Clear ();
76                         List.Clear ();
77                 }
78         
79                 public bool Contains (SchemaImporterExtension extension)
80                 {
81                         if (extension == null)
82                                 throw new ArgumentNullException ("extension");
83                         foreach (SchemaImporterExtension e in List)
84                                 if (extension.Equals (e))
85                                         return true;
86                         return false;
87                 }
88                 
89                 public void CopyTo (SchemaImporterExtension [] array, int index)
90                 {
91                         List.CopyTo (array, index);
92                 }
93                 
94                 public int IndexOf (SchemaImporterExtension extension)
95                 {
96                         if (extension == null)
97                                 throw new ArgumentNullException ("extension");
98                         int i = 0;
99                         foreach (SchemaImporterExtension e in List) {
100                                 if (extension.Equals (e)) {
101                                         return i;
102                                 }
103                                 i++;
104                         }
105                         return -1;
106                 }
107                 
108                 public void Insert (int index, SchemaImporterExtension extension)
109                 {
110                         if (extension == null)
111                                 throw new ArgumentNullException ("extension");
112                         List.Insert (index, extension);
113                 }
114                 
115                 public void Remove (SchemaImporterExtension extension)
116                 {
117                         int idx = IndexOf (extension);
118                         if (idx >= 0)
119                                 List.RemoveAt (idx);
120                 }
121                 
122                 public void Remove (string name)
123                 {
124                         if (name == null)
125                                 throw new ArgumentNullException ("name");
126                         if (!named_items.ContainsKey (name))
127                                 return;
128                         SchemaImporterExtension e = named_items [name];
129                         Remove (e);
130                         named_items.Remove (name);
131                 }
132                 
133                 public SchemaImporterExtension this [int index] 
134                 {
135                         get { return (SchemaImporterExtension) List [index]; }
136                         set { List [index] = value; }
137                 }
138         }
139 }
140
141 #endif