Ref parameter was not covered by ParameterInfo.IsOut. Fixed bug #696784.
[mono.git] / mcs / class / System.ServiceModel / System.ServiceModel.Configuration / ServiceModelExtensionCollectionElement.cs
1 //
2 // ServiceModelExtensionCollectionElement.cs
3 //
4 // Author:
5 //      Atsushi Enomoto <atsushi@ximian.com>
6 //
7 // Copyright (C) 2006 Novell, Inc.  http://www.novell.com
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 // 
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 // 
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
28 using System;
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Configuration;
32 using System.Xml;
33
34 namespace System.ServiceModel.Configuration
35 {
36         public abstract class ServiceModelExtensionCollectionElement<TServiceModelExtensionElement> : ConfigurationElement,
37                 ICollection<TServiceModelExtensionElement>,
38                 IEnumerable<TServiceModelExtensionElement>,
39                 IEnumerable
40                 where TServiceModelExtensionElement : ServiceModelExtensionElement
41         {
42                 internal ServiceModelExtensionCollectionElement ()
43                 {
44                 }
45
46                 ConfigurationPropertyCollection properties;
47
48                 KeyedByTypeCollection<TServiceModelExtensionElement> _list = new KeyedByTypeCollection<TServiceModelExtensionElement> ();
49                 bool is_modified;
50
51                 public virtual void Add (TServiceModelExtensionElement element)
52                 {
53                         is_modified = true;
54                         _list.Add (element);
55                 }
56                 
57                 public virtual bool CanAdd (TServiceModelExtensionElement element) {
58                         throw new NotImplementedException ();
59                 }
60
61                 public void Clear ()
62                 {
63                         is_modified = true;
64                         _list.Clear ();
65                 }
66
67                 public bool Contains (TServiceModelExtensionElement element)
68                 {
69                         return _list.Contains (element);
70                 }
71
72                 public bool ContainsKey (string elementName)
73                 {
74                         throw new NotImplementedException ();
75                 }
76
77                 public bool ContainsKey (Type elementType)
78                 {
79                         return _list.Contains (elementType);
80                 }
81
82                 public void CopyTo (TServiceModelExtensionElement[] elements,
83                         int start)
84                 {
85                         throw new NotImplementedException ();
86                 }
87
88                 public IEnumerator<TServiceModelExtensionElement> GetEnumerator () {
89                         for (int i = 0; i < Count; i++)
90                                 yield return this [i];
91                 }
92
93                 public bool Remove (TServiceModelExtensionElement element)
94                 {
95                         is_modified = true;
96                         return _list.Remove (element.GetType ());
97                 }
98
99                 IEnumerator IEnumerable.GetEnumerator ()
100                 {
101                         return GetEnumerator ();
102                 }
103
104                 bool ICollection<TServiceModelExtensionElement>.IsReadOnly {
105                         get { throw new NotImplementedException (); }
106                 }
107
108                 public TServiceModelExtensionElement this [int index] {
109                         get {
110                                 return _list [index];
111                         }
112                 }
113
114                 public TServiceModelExtensionElement this [Type extensionType] {
115                         get {
116                                 if (_list.Contains (extensionType))
117                                         return _list [extensionType];
118                                 return null;
119                         }
120                 }
121
122                 protected override void DeserializeElement (XmlReader reader, bool serializeCollectionKey)
123                 {
124                         base.DeserializeElement (reader, serializeCollectionKey);
125                 }
126
127                 protected override bool OnDeserializeUnrecognizedElement (string elementName, XmlReader reader) {
128                         TServiceModelExtensionElement ext= DeserializeExtensionElement (elementName, reader);
129                         if (ext == null)
130                                 return false;
131                         Add (ext);
132                         return true;
133                 }
134
135                 internal virtual TServiceModelExtensionElement DeserializeExtensionElement (string elementName, XmlReader reader) {
136                         return null;
137                 }
138
139                 public int Count {
140                         get { return _list.Count; }
141                 }
142
143                 protected override void Reset (ConfigurationElement parentElement)
144                 {
145                         base.Reset (parentElement);
146                         var parent = (ServiceModelExtensionCollectionElement<TServiceModelExtensionElement>) parentElement;
147
148 #if true
149                         foreach (var item in parent)
150                                 Add (item);
151 #else // FIXME: no way to call Reset() on item (hence disabled now)
152                         // It is based on ConfigurationElementCollection.Reset()
153                         for (int n=0; n<parent.Count; n++)
154                         {
155                                 var parentItem = parent [n];
156 //                              ConfigurationElement item = CreateNewElementInternal (null);
157                                 var item = (TServiceModelExtensionElement) Activator.CreateInstance (parentItem.GetType ()); // FIXME: there is no assureance on default constructor existence.
158                                 item.Reset (parentItem);
159                                 Add (item);
160                         }
161 #endif
162                 }
163
164                 protected override bool IsModified ()
165                 {
166                         return is_modified;
167                 }
168
169                 protected override void ResetModified ()
170                 {
171                         is_modified = false;
172                 }
173
174                 protected void SetIsModified ()
175                 {
176                         is_modified = true;
177                 }
178
179                 protected override ConfigurationPropertyCollection Properties {
180                         get {
181                                 if (properties == null) {
182                                         properties = base.Properties;
183                                 }
184                                 return properties;
185                         }
186                 }
187         }
188 }