Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add IDictionary support to Document but as explicit interface impleme…

…ntation.
  • Loading branch information...
commit 67e6c3b2912e680793040fc45bfb5118c3b34c8f 1 parent 69e7c91
Steve Wagner authored July 07, 2010

Showing 1 changed file with 167 additions and 9 deletions. Show diff stats Hide diff stats

  1. 176  source/MongoDB/Document.cs
176  source/MongoDB/Document.cs
@@ -13,7 +13,7 @@ namespace MongoDB
13 13
     /// Description of Document.
14 14
     /// </summary>
15 15
     [Serializable]
16  
-    public class Document : IDictionary<string,object>, IXmlSerializable
  16
+    public class Document : IDictionary<string,object>, IDictionary, IXmlSerializable
17 17
     {
18 18
         private readonly List<string> _orderedKeys;
19 19
         private readonly Dictionary<string,object > _dictionary;
@@ -75,6 +75,30 @@ public Document(IEnumerable<KeyValuePair<string, object>> dictionary)
75 75
         }
76 76
 
77 77
         /// <summary>
  78
+        /// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the keys of the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
  79
+        /// </summary>
  80
+        /// <value></value>
  81
+        /// <returns>
  82
+        /// An <see cref="T:System.Collections.Generic.ICollection`1"/> containing the keys of the object that implements <see cref="T:System.Collections.Generic.IDictionary`2"/>.
  83
+        /// </returns>
  84
+        ICollection IDictionary.Keys
  85
+        {
  86
+            get { return _dictionary.Keys; }
  87
+        }
  88
+
  89
+        /// <summary>
  90
+        /// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the values in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
  91
+        /// </summary>
  92
+        /// <value></value>
  93
+        /// <returns>
  94
+        /// An <see cref="T:System.Collections.Generic.ICollection`1"/> containing the values in the object that implements <see cref="T:System.Collections.Generic.IDictionary`2"/>.
  95
+        /// </returns>
  96
+        ICollection IDictionary.Values
  97
+        {
  98
+            get { return _dictionary.Values; }
  99
+        }
  100
+
  101
+        /// <summary>
78 102
         /// Gets an <see cref="T:System.Collections.Generic.ICollection`1"/> containing the values in the <see cref="T:System.Collections.Generic.IDictionary`2"/>.
79 103
         /// </summary>
80 104
         /// <value></value>
@@ -310,6 +334,42 @@ public Document Merge(Document source)
310 334
         }
311 335
 
312 336
         /// <summary>
  337
+        /// Determines whether the <see cref="T:System.Collections.IDictionary"/> object contains an element with the specified key.
  338
+        /// </summary>
  339
+        /// <param name="key">The key to locate in the <see cref="T:System.Collections.IDictionary"/> object.</param>
  340
+        /// <returns>
  341
+        /// true if the <see cref="T:System.Collections.IDictionary"/> contains an element with the key; otherwise, false.
  342
+        /// </returns>
  343
+        /// <exception cref="T:System.ArgumentNullException">
  344
+        /// 	<paramref name="key"/> is null.
  345
+        /// </exception>
  346
+        bool IDictionary.Contains(object key)
  347
+        {
  348
+            return _orderedKeys.Contains(Convert.ToString(key));
  349
+        }
  350
+
  351
+        /// <summary>
  352
+        /// Adds an element with the provided key and value to the <see cref="T:System.Collections.IDictionary"/> object.
  353
+        /// </summary>
  354
+        /// <param name="key">The <see cref="T:System.Object"/> to use as the key of the element to add.</param>
  355
+        /// <param name="value">The <see cref="T:System.Object"/> to use as the value of the element to add.</param>
  356
+        /// <exception cref="T:System.ArgumentNullException">
  357
+        /// 	<paramref name="key"/> is null.
  358
+        /// </exception>
  359
+        /// <exception cref="T:System.ArgumentException">
  360
+        /// An element with the same key already exists in the <see cref="T:System.Collections.IDictionary"/> object.
  361
+        /// </exception>
  362
+        /// <exception cref="T:System.NotSupportedException">
  363
+        /// The <see cref="T:System.Collections.IDictionary"/> is read-only.
  364
+        /// -or-
  365
+        /// The <see cref="T:System.Collections.IDictionary"/> has a fixed size.
  366
+        /// </exception>
  367
+        void IDictionary.Add(object key, object value)
  368
+        {
  369
+            Add(Convert.ToString(key), value);
  370
+        }
  371
+
  372
+        /// <summary>
313 373
         /// Clears the contents of the <see cref="T:System.Collections.DictionaryBase"/> instance.
314 374
         /// </summary>
315 375
         /// <exception cref="T:System.NotSupportedException">
@@ -321,6 +381,44 @@ public Document Merge(Document source)
321 381
         }
322 382
 
323 383
         /// <summary>
  384
+        /// Returns an <see cref="T:System.Collections.IDictionaryEnumerator"/> object for the <see cref="T:System.Collections.IDictionary"/> object.
  385
+        /// </summary>
  386
+        /// <returns>
  387
+        /// An <see cref="T:System.Collections.IDictionaryEnumerator"/> object for the <see cref="T:System.Collections.IDictionary"/> object.
  388
+        /// </returns>
  389
+        IDictionaryEnumerator IDictionary.GetEnumerator()
  390
+        {
  391
+            return ( (IDictionary)_dictionary ).GetEnumerator();
  392
+        }
  393
+
  394
+        /// <summary>
  395
+        /// Removes the element with the specified key from the <see cref="T:System.Collections.IDictionary"/> object.
  396
+        /// </summary>
  397
+        /// <param name="key">The key of the element to remove.</param>
  398
+        /// <exception cref="T:System.ArgumentNullException">
  399
+        /// 	<paramref name="key"/> is null.
  400
+        /// </exception>
  401
+        /// <exception cref="T:System.NotSupportedException">
  402
+        /// The <see cref="T:System.Collections.IDictionary"/> object is read-only.
  403
+        /// -or-
  404
+        /// The <see cref="T:System.Collections.IDictionary"/> has a fixed size.
  405
+        /// </exception>
  406
+        void IDictionary.Remove(object key)
  407
+        {
  408
+            Remove(Convert.ToString(key));
  409
+        }
  410
+
  411
+        /// <summary>
  412
+        /// Gets or sets the <see cref="System.Object"/> with the specified key.
  413
+        /// </summary>
  414
+        /// <value></value>
  415
+        object IDictionary.this[object key]
  416
+        {
  417
+            get { return Get(Convert.ToString(key)); }
  418
+            set { Set(Convert.ToString(key), value); }
  419
+        }
  420
+
  421
+        /// <summary>
324 422
         /// Determines whether the <see cref="T:System.Collections.Generic.ICollection`1"/> contains a specific value.
325 423
         /// </summary>
326 424
         /// <param name="item">The object to locate in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</param>
@@ -339,17 +437,17 @@ public Document Merge(Document source)
339 437
         void ICollection<KeyValuePair<string, object>>.CopyTo(KeyValuePair<string, object>[] array, int arrayIndex){
340 438
             ((ICollection<KeyValuePair<string, object>>)_dictionary).CopyTo(array,arrayIndex);
341 439
         }
342  
-        
343  
-        /// <summary>
344  
-        /// TODO Fix any accidental reordering issues.
345  
-        /// </summary>
346  
-        /// <param name="destinationDocument">The dest.</param>
  440
+
  441
+        /// <summary>
  442
+        /// Copies to items to destinationDocument.
  443
+        /// </summary>
  444
+        /// <param name="destinationDocument">The destination document.</param>
347 445
         public void CopyTo(Document destinationDocument){
348 446
             if(destinationDocument == null)
349 447
                 throw new ArgumentNullException("destinationDocument");
350 448
             
351  
-            //Todo: Fix any accidental reordering issues.
352  
-
  449
+            //Todo: Fix any accidental reordering issues.
  450
+
353 451
             foreach(var key in _orderedKeys){
354 452
                 if(destinationDocument.Contains(key))
355 453
                     destinationDocument.Remove(key);
@@ -372,7 +470,33 @@ public Document Merge(Document source)
372 470
                 _orderedKeys.Remove(item.Key);
373 471
             return removed;
374 472
         }
375  
-        
  473
+
  474
+        /// <summary>
  475
+        /// Copies the elements of the <see cref="T:System.Collections.ICollection"/> to an <see cref="T:System.Array"/>, starting at a particular <see cref="T:System.Array"/> index.
  476
+        /// </summary>
  477
+        /// <param name="array">The one-dimensional <see cref="T:System.Array"/> that is the destination of the elements copied from <see cref="T:System.Collections.ICollection"/>. The <see cref="T:System.Array"/> must have zero-based indexing.</param>
  478
+        /// <param name="index">The zero-based index in <paramref name="array"/> at which copying begins.</param>
  479
+        /// <exception cref="T:System.ArgumentNullException">
  480
+        /// 	<paramref name="array"/> is null.
  481
+        /// </exception>
  482
+        /// <exception cref="T:System.ArgumentOutOfRangeException">
  483
+        /// 	<paramref name="index"/> is less than zero.
  484
+        /// </exception>
  485
+        /// <exception cref="T:System.ArgumentException">
  486
+        /// 	<paramref name="array"/> is multidimensional.
  487
+        /// -or-
  488
+        /// <paramref name="index"/> is equal to or greater than the length of <paramref name="array"/>.
  489
+        /// -or-
  490
+        /// The number of elements in the source <see cref="T:System.Collections.ICollection"/> is greater than the available space from <paramref name="index"/> to the end of the destination <paramref name="array"/>.
  491
+        /// </exception>
  492
+        /// <exception cref="T:System.ArgumentException">
  493
+        /// The type of the source <see cref="T:System.Collections.ICollection"/> cannot be cast automatically to the type of the destination <paramref name="array"/>.
  494
+        /// </exception>
  495
+        void ICollection.CopyTo(Array array, int index)
  496
+        {
  497
+            ((ICollection)_dictionary).CopyTo(array,index);
  498
+        }
  499
+
376 500
         /// <summary>
377 501
         /// Gets the number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.
378 502
         /// </summary>
@@ -385,6 +509,29 @@ public Document Merge(Document source)
385 509
         }
386 510
 
387 511
         /// <summary>
  512
+        /// Gets an object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.
  513
+        /// </summary>
  514
+        /// <value></value>
  515
+        /// <returns>
  516
+        /// An object that can be used to synchronize access to the <see cref="T:System.Collections.ICollection"/>.
  517
+        /// </returns>
  518
+        object ICollection.SyncRoot
  519
+        {
  520
+            get { return _orderedKeys; /* no special object is need since _orderedKeys is internal.*/ }
  521
+        }
  522
+
  523
+        /// <summary>
  524
+        /// Gets a value indicating whether access to the <see cref="T:System.Collections.ICollection"/> is synchronized (thread safe).
  525
+        /// </summary>
  526
+        /// <value></value>
  527
+        /// <returns>true if access to the <see cref="T:System.Collections.ICollection"/> is synchronized (thread safe); otherwise, false.
  528
+        /// </returns>
  529
+        bool ICollection.IsSynchronized
  530
+        {
  531
+            get { return false; }
  532
+        }
  533
+
  534
+        /// <summary>
388 535
         /// Gets a value indicating whether the <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only.
389 536
         /// </summary>
390 537
         /// <value></value>
@@ -395,6 +542,17 @@ public Document Merge(Document source)
395 542
         }
396 543
 
397 544
         /// <summary>
  545
+        /// Gets a value indicating whether the <see cref="T:System.Collections.IDictionary"/> object has a fixed size.
  546
+        /// </summary>
  547
+        /// <value></value>
  548
+        /// <returns>true if the <see cref="T:System.Collections.IDictionary"/> object has a fixed size; otherwise, false.
  549
+        /// </returns>
  550
+        bool IDictionary.IsFixedSize
  551
+        {
  552
+            get { return false; }
  553
+        }
  554
+
  555
+        /// <summary>
398 556
         /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
399 557
         /// </summary>
400 558
         /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>

0 notes on commit 67e6c3b

Please sign in to comment.
Something went wrong with that request. Please try again.