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.
35 using System.Collections;
36 using System.Collections.Generic;
38 namespace System.Xml.Serialization.Advanced
40 public class SchemaImporterExtensionCollection : CollectionBase
42 Dictionary<string,SchemaImporterExtension> named_items =
43 new Dictionary<string,SchemaImporterExtension> ();
45 public SchemaImporterExtensionCollection ()
49 public int Add (SchemaImporterExtension extension)
51 if (extension == null)
52 throw new ArgumentNullException ("extension");
53 return List.Add (extension);
56 public int Add (string key, Type type)
59 throw new ArgumentNullException ("key");
61 throw new ArgumentNullException ("type");
62 if (!type.IsSubclassOf (typeof (SchemaImporterExtension)))
63 throw new ArgumentException ("The type argument must be subclass of SchemaImporterExtension.");
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));
69 named_items.Add (key, e);
73 public new void Clear ()
79 public bool Contains (SchemaImporterExtension extension)
81 if (extension == null)
82 throw new ArgumentNullException ("extension");
83 foreach (SchemaImporterExtension e in List)
84 if (extension.Equals (e))
89 public void CopyTo (SchemaImporterExtension [] array, int index)
91 List.CopyTo (array, index);
94 public int IndexOf (SchemaImporterExtension extension)
96 if (extension == null)
97 throw new ArgumentNullException ("extension");
99 foreach (SchemaImporterExtension e in List) {
100 if (extension.Equals (e)) {
108 public void Insert (int index, SchemaImporterExtension extension)
110 if (extension == null)
111 throw new ArgumentNullException ("extension");
112 List.Insert (index, extension);
115 public void Remove (SchemaImporterExtension extension)
117 int idx = IndexOf (extension);
122 public void Remove (string name)
125 throw new ArgumentNullException ("name");
126 if (!named_items.ContainsKey (name))
128 SchemaImporterExtension e = named_items [name];
130 named_items.Remove (name);
133 public SchemaImporterExtension this [int index]
135 get { return (SchemaImporterExtension) List [index]; }
136 set { List [index] = value; }