From 481b6ac3166a4c7d801207515c79bccfc9e76e6d Mon Sep 17 00:00:00 2001 From: Justin Dearing Date: Fri, 4 Mar 2011 17:02:12 -0500 Subject: [PATCH] Made the implicit cast a constructor. This does not break the example, but it does make it harder to accidently call from C#. --- Bson/ObjectModel/BsonDocument.cs | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/Bson/ObjectModel/BsonDocument.cs b/Bson/ObjectModel/BsonDocument.cs index 2366323d27..5c4f5272a0 100644 --- a/Bson/ObjectModel/BsonDocument.cs +++ b/Bson/ObjectModel/BsonDocument.cs @@ -130,21 +130,18 @@ namespace MongoDB.Bson { : base(BsonType.Document) { Add(name, value); } - #endregion - #region public operators /// /// Converts a Hashtable into a BsonDocument. /// /// - /// The main advantage for this implicit cast is to ease use of the Bson library and MongoDB driver with Windows Powershell. - /// Powershell has native support for Hashtables. + /// The intended usage of this constructor is to ease the use of the Bson library and MongoDB driver with Windows Powershell. + /// Powershell has native support for Hashtables via its @{"key1"= "value1; "key2"= "value2; . . .} notation. /// /// /// A Hashtable. The keys in this hashtable must be such that when key.ToString() /// is called on them their values is unique. /// - /// A BsonDocument /// /// Using this implicit cast to create a BsonDocument with PowerShell's Hashtable notation: /// @@ -174,14 +171,14 @@ namespace MongoDB.Bson { ///
///
/// - public static implicit operator BsonDocument(Hashtable ht) - { - var doc = new BsonDocument(); + public BsonDocument( + Hashtable ht + ) + : base(BsonType.Document) { foreach (var key in ht.Keys) { - doc.Add(key.ToString(), BsonValue.Create(ht[key])); + this.Add(key.ToString(), BsonValue.Create(ht[key])); } - return doc; } #endregion