[runtime] Overwrite stacktrace for exception on re-throw. Fixes #1856.
[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
33 using System;
34 using System.Collections;
35 using System.Collections.Generic;
36
37 namespace System.Xml.Serialization.Advanced
38 {
39         public class SchemaImporterExtensionCollection : CollectionBase
40         {
41                 Dictionary<string,SchemaImporterExtension> named_items =
42                         new Dictionary<string,SchemaImporterExtension> ();
43
44                 public SchemaImporterExtensionCollection ()
45                 {
46                 }
47
48                 public int Add (SchemaImporterExtension extension)
49                 {
50                         if (extension == null)
51                                 throw new ArgumentNullException ("extension");
52                         return List.Add (extension);
53                 }
54
55                 public int Add (string name, Type type)
56                 {
57                         if (name == null)
58                                 throw new ArgumentNullException ("name");
59                         if (type == null)
60                                 throw new ArgumentNullException ("type");
61                         if (!type.IsSubclassOf (typeof (SchemaImporterExtension)))
62                                 throw new ArgumentException ("The type argument must be subclass of SchemaImporterExtension.");
63
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));
67                         int ret = Add (e);
68                         named_items.Add (name, e);
69                         return ret;
70                 }
71         
72                 public new void Clear ()
73                 {
74                         named_items.Clear ();
75                         List.Clear ();
76                 }
77         
78                 public bool Contains (SchemaImporterExtension extension)
79                 {
80                         if (extension == null)
81                                 throw new ArgumentNullException ("extension");
82                         foreach (SchemaImporterExtension e in List)
83                                 if (extension.Equals (e))
84                                         return true;
85                         return false;
86                 }
87                 
88                 public void CopyTo (SchemaImporterExtension [] array, int index)
89                 {
90                         List.CopyTo (array, index);
91                 }
92                 
93                 public int IndexOf (SchemaImporterExtension extension)
94                 {
95                         if (extension == null)
96                                 throw new ArgumentNullException ("extension");
97                         int i = 0;
98                         foreach (SchemaImporterExtension e in List) {
99                                 if (extension.Equals (e)) {
100                                         return i;
101                                 }
102                                 i++;
103                         }
104                         return -1;
105                 }
106                 
107                 public void Insert (int index, SchemaImporterExtension extension)
108                 {
109                         if (extension == null)
110                                 throw new ArgumentNullException ("extension");
111                         List.Insert (index, extension);
112                 }
113                 
114                 public void Remove (SchemaImporterExtension extension)
115                 {
116                         int idx = IndexOf (extension);
117                         if (idx >= 0)
118                                 List.RemoveAt (idx);
119                 }
120                 
121                 public void Remove (string name)
122                 {
123                         if (name == null)
124                                 throw new ArgumentNullException ("name");
125                         if (!named_items.ContainsKey (name))
126                                 return;
127                         SchemaImporterExtension e = named_items [name];
128                         Remove (e);
129                         named_items.Remove (name);
130                 }
131                 
132                 public SchemaImporterExtension this [int index] 
133                 {
134                         get { return (SchemaImporterExtension) List [index]; }
135                         set { List [index] = value; }
136                 }
137         }
138 }
139