2 // MessageProperties.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
29 using System.Collections;
30 using System.Collections.Generic;
31 using System.Collections.ObjectModel;
32 using System.ServiceModel.Channels;
33 using System.ServiceModel.Security;
35 using Pair = System.Collections.Generic.KeyValuePair<string, object>;
37 namespace System.ServiceModel.Channels
39 [MonoTODO ("it's untested")]
40 public sealed class MessageProperties : IDictionary<string, object>,
41 ICollection<Pair>, IEnumerable<Pair>, IEnumerable, IDisposable
43 bool allow_output_batch;
44 MessageEncoder encoder;
48 public MessageProperties ()
50 list = new List<Pair> ();
53 public MessageProperties (MessageProperties properties)
55 properties.CopyProperties (this);
58 [MonoTODO ("This should actually be internal of a property.")]
59 public bool AllowOutputBatching {
60 get { return allow_output_batch; }
61 set { allow_output_batch = value; }
65 get { return list.Count; }
68 [MonoTODO ("This should actually be internal of a property.")]
69 public MessageEncoder Encoder {
70 get { return encoder; }
71 set { encoder = value; }
74 public bool IsFixedSize {
78 public bool IsReadOnly {
82 public ICollection<string> Keys {
83 get { return new ParameterKeyCollection (list); }
86 public object this [string name] {
88 for (int i = 0; i < list.Count; i++)
89 if (list [i].Key == name)
90 return list [i].Value;
94 for (int i = 0; i < list.Count; i++)
95 if (list [i].Key == name) {
96 list [i] = new Pair (name, value);
99 list.Add (new Pair (name, value));
104 public SecurityMessageProperty Security {
105 get { return (SecurityMessageProperty) this ["Security"]; }
106 set { this ["Security"] = value; }
110 public ICollection<object> Values {
111 get { return new ParameterValueCollection (list); }
114 [MonoTODO ("This should actually be internal of a property.")]
120 public void Add (string name, object property)
122 list.Add (new Pair (name, property));
130 public bool ContainsKey (string name)
132 for (int i = 0; i < list.Count; i++)
133 if (list [i].Key == name)
138 public void CopyProperties (MessageProperties properties)
140 list = new List<Pair> (properties.list);
141 allow_output_batch = properties.allow_output_batch;
142 encoder = properties.encoder;
143 via = properties.via;
146 public void Dispose ()
150 public bool Remove (string name)
152 for (int i = 0; i < list.Count; i++)
153 if (list [i].Key == name) {
160 public bool TryGetValue (string name, out object value)
162 for (int i = 0; i < list.Count; i++)
163 if (list [i].Key == name) {
164 value = list [i].Value;
171 void ICollection<Pair>.Add (Pair pair)
176 bool ICollection<Pair>.Contains (Pair pair)
178 return list.Contains (pair);
181 void ICollection<Pair>.CopyTo (Pair [] array, int index)
183 list.CopyTo (array, index);
186 bool ICollection<Pair>.Remove (Pair pair)
188 return list.Remove (pair);
191 IEnumerator<Pair> IEnumerable<Pair>.GetEnumerator ()
193 return list.GetEnumerator ();
196 IEnumerator IEnumerable.GetEnumerator ()
198 return (IEnumerator) ((IEnumerable<Pair>) this).GetEnumerator ();
201 class ParameterKeyCollection : ICollection<string>
205 public ParameterKeyCollection (List<Pair> source)
207 this.source = source;
211 get { return source.Count; }
214 public bool IsReadOnly {
218 public void Add (string item)
220 throw new InvalidOperationException ();
225 throw new InvalidOperationException ();
228 public bool Contains (string item)
230 for (int i = 0; i < source.Count; i++)
231 if (source [i].Key == item)
236 public void CopyTo (string [] array, int index)
238 for (int i = 0; i < source.Count; i++)
239 array [index + i] = source [i].Key;
242 public IEnumerator<string> GetEnumerator ()
244 foreach (Pair p in source)
248 IEnumerator IEnumerable.GetEnumerator ()
250 foreach (Pair p in source)
254 public bool Remove (string item)
256 throw new InvalidOperationException ();
260 class ParameterValueCollection : ICollection<object>
264 public ParameterValueCollection (List<Pair> source)
266 this.source = source;
270 get { return source.Count; }
273 public bool IsReadOnly {
277 public void Add (object item)
279 throw new InvalidOperationException ();
284 throw new InvalidOperationException ();
287 public bool Contains (object item)
289 for (int i = 0; i < source.Count; i++)
290 if (source [i].Value == item)
295 public void CopyTo (object [] array, int index)
297 for (int i = 0; i < source.Count; i++)
298 array [index + i] = source [i].Value;
301 public IEnumerator<object> GetEnumerator ()
303 foreach (Pair p in source)
304 yield return p.Value;
307 IEnumerator IEnumerable.GetEnumerator ()
309 foreach (Pair p in source)
313 public bool Remove (object item)
315 throw new InvalidOperationException ();