2 // System.Xml.Serialization.SchemaImporterExtensionCollection.cs
5 // Lluis Sanchez Gual (lluis@novell.com)
6 // Atsushi Enomoto (atsushi@ximian.com)
8 // Copyright (C) Novell, Inc., 2004, 2006
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:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
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.
34 using System.Collections;
35 using System.Collections.Generic;
37 namespace System.Xml.Serialization.Advanced
39 public class SchemaImporterExtensionCollection : CollectionBase
41 Dictionary<string,SchemaImporterExtension> named_items =
42 new Dictionary<string,SchemaImporterExtension> ();
44 public SchemaImporterExtensionCollection ()
48 public int Add (SchemaImporterExtension extension)
50 if (extension == null)
51 throw new ArgumentNullException ("extension");
52 return List.Add (extension);
55 public int Add (string name, Type type)
58 throw new ArgumentNullException ("name");
60 throw new ArgumentNullException ("type");
61 if (!type.IsSubclassOf (typeof (SchemaImporterExtension)))
62 throw new ArgumentException ("The type argument must be subclass of SchemaImporterExtension.");
64 SchemaImporterExtension e = (SchemaImporterExtension) Activator.CreateInstance (type);
65 if (named_items.ContainsKey (name))
66 throw new InvalidOperationException (String.Format ("A SchemaImporterExtension keyed by '{0}' already exists.", name));
68 named_items.Add (name, e);
72 public new void Clear ()
78 public bool Contains (SchemaImporterExtension extension)
80 if (extension == null)
81 throw new ArgumentNullException ("extension");
82 foreach (SchemaImporterExtension e in List)
83 if (extension.Equals (e))
88 public void CopyTo (SchemaImporterExtension [] array, int index)
90 List.CopyTo (array, index);
93 public int IndexOf (SchemaImporterExtension extension)
95 if (extension == null)
96 throw new ArgumentNullException ("extension");
98 foreach (SchemaImporterExtension e in List) {
99 if (extension.Equals (e)) {
107 public void Insert (int index, SchemaImporterExtension extension)
109 if (extension == null)
110 throw new ArgumentNullException ("extension");
111 List.Insert (index, extension);
114 public void Remove (SchemaImporterExtension extension)
116 int idx = IndexOf (extension);
121 public void Remove (string name)
124 throw new ArgumentNullException ("name");
125 if (!named_items.ContainsKey (name))
127 SchemaImporterExtension e = named_items [name];
129 named_items.Remove (name);
132 public SchemaImporterExtension this [int index]
134 get { return (SchemaImporterExtension) List [index]; }
135 set { List [index] = value; }