Skip to content

Commit

Permalink
Removed the Wrap methods from BsonDocument and the Builder classes. T…
Browse files Browse the repository at this point in the history
…hese methods were originally added for the convenience of the driver internally. However, users should almost never be calling Xyz.Wrap, and the very existence of these methods causes confusion. Any code that was legitimately calling Xyz.Wrap can just call XyzWrapper.Create instead.
  • Loading branch information
rstam committed Mar 20, 2011
1 parent 6f9e959 commit 1944480
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 203 deletions.
32 changes: 0 additions & 32 deletions Bson/ObjectModel/BsonDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,38 +401,6 @@ string filename
return ReadFrom(bsonReader);
}
}

/// <summary>
/// Wraps an object with a BsonDocumentWrapper.
/// </summary>
/// <typeparam name="TNominalType">The nominal type of the wrapped object.</typeparam>
/// <param name="value">The wrapped object.</param>
/// <returns>A BsonDocumentWrapper.</returns>
public static BsonDocumentWrapper Wrap<TNominalType>(
TNominalType value
) {
if (value != null) {
return new BsonDocumentWrapper(typeof(TNominalType), value);
} else {
return null;
}
}

/// <summary>
/// Wraps multiple objects with a list of BsonDocumentWrappers.
/// </summary>
/// <typeparam name="TNominalType">The nominal type of the wrapped objects.</typeparam>
/// <param name="values">The wrapped objects.</param>
/// <returns>A list of BsonDocumentWrappers.</returns>
public static IEnumerable<BsonDocumentWrapper> WrapMultiple<TNominalType>(
IEnumerable<TNominalType> values
) {
if (values != null) {
return values.Where(v => v != null).Select(v => new BsonDocumentWrapper(typeof(TNominalType), v));
} else {
return null;
}
}
#endregion

#region public methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public void TestNull() {

[Test]
public void TestEmpty() {
var obj = new TestClass(new BsonDocumentWrapper(new BsonDocument()));
var obj = new TestClass(BsonDocumentWrapper.Create(new BsonDocument()));
var json = obj.ToJson();
var expected = "{ 'B' : #, 'V' : # }".Replace("#", "{ }").Replace("'", "\"");
Assert.AreEqual(expected, json);
Expand All @@ -432,7 +432,7 @@ public void TestEmpty() {
[Test]
public void TestNotEmpty() {
var obj = new TestClass(
new BsonDocumentWrapper(
BsonDocumentWrapper.Create(
new BsonDocument {
{ "A", 1 },
{ "B", 2 }
Expand Down
11 changes: 0 additions & 11 deletions Driver/Builders/CollectionOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ long value
) {
return new CollectionOptionsBuilder().SetMaxSize(value);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoCollectionOptions is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="options">The wrapped object.</param>
/// <returns>A CollectionOptionsWrapper.</returns>
public static IMongoCollectionOptions Wrap(
object options
) {
return CollectionOptionsWrapper.Create(options);
}
#endregion
}

Expand Down
12 changes: 0 additions & 12 deletions Driver/Builders/FieldsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;

namespace MongoDB.Driver.Builders {
/// <summary>
Expand Down Expand Up @@ -88,17 +87,6 @@ int limit
) {
return new FieldsBuilder().Slice(name, skip, limit);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoFields is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="fields">The wrapped object.</param>
/// <returns>A FieldsWrapper.</returns>
public static IMongoFields Wrap(
object fields
) {
return FieldsWrapper.Create(fields);
}
#endregion
}

Expand Down
12 changes: 0 additions & 12 deletions Driver/Builders/GeoNearOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;

namespace MongoDB.Driver.Builders {
/// <summary>
Expand Down Expand Up @@ -71,17 +70,6 @@ bool value
) {
return new GeoNearOptionsBuilder().SetSpherical(value);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoGeoNearOptions is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="options">The wrapped object.</param>
/// <returns>A GeoNearOptionsWrapper.</returns>
public static IMongoGeoNearOptions Wrap(
object options
) {
return GeoNearOptionsWrapper.Create(options);
}
#endregion
}

Expand Down
12 changes: 0 additions & 12 deletions Driver/Builders/GroupByBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;

namespace MongoDB.Driver.Builders {
/// <summary>
Expand Down Expand Up @@ -51,17 +50,6 @@ params string[] names
) {
return new GroupByBuilder(names);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoGroupBy is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="groupBy">The wrapped object.</param>
/// <returns>A GroupByWrapper.</returns>
public static IMongoGroupBy Wrap(
object groupBy
) {
return GroupByWrapper.Create(groupBy);
}
#endregion
}

Expand Down
12 changes: 0 additions & 12 deletions Driver/Builders/IndexKeysBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;

namespace MongoDB.Driver.Builders {
/// <summary>
Expand Down Expand Up @@ -62,17 +61,6 @@ string name
) {
return new IndexKeysBuilder().GeoSpatial(name);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoIndexKeys is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="keys">The wrapped object.</param>
/// <returns>A IndexKeysWrapper.</returns>
public static IMongoIndexKeys Wrap(
object keys
) {
return IndexKeysWrapper.Create(keys);
}
#endregion
}

Expand Down
12 changes: 0 additions & 12 deletions Driver/Builders/IndexOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;

namespace MongoDB.Driver.Builders {
/// <summary>
Expand Down Expand Up @@ -106,17 +105,6 @@ bool value
) {
return new IndexOptionsBuilder().SetUnique(value);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoIndexOptions is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="options">The wrapped object.</param>
/// <returns>A IndexOptionsWrapper.</returns>
public static IMongoIndexOptions Wrap(
object options
) {
return IndexOptionsWrapper.Create(options);
}
#endregion
}

Expand Down
18 changes: 3 additions & 15 deletions Driver/Builders/MapReduceOptionsBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;

namespace MongoDB.Driver.Builders {
/// <summary>
Expand Down Expand Up @@ -224,17 +223,6 @@ bool value
) {
return new MapReduceOptionsBuilder().SetVerbose(value);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoMapReduceOptions is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="options">The wrapped object.</param>
/// <returns>A MapReduceOptionsWrapper.</returns>
public static IMongoMapReduceOptions Wrap(
object options
) {
return MapReduceOptionsWrapper.Create(options);
}
#endregion
}

Expand Down Expand Up @@ -313,7 +301,7 @@ MapReduceOutput output
public MapReduceOptionsBuilder SetQuery(
IMongoQuery query
) {
document["query"] = BsonDocument.Wrap(query);
document["query"] = BsonDocumentWrapper.Create(query);
return this;
}

Expand All @@ -325,7 +313,7 @@ IMongoQuery query
public MapReduceOptionsBuilder SetScope(
IMongoScope scope
) {
document["scope"] = BsonDocument.Wrap(scope);
document["scope"] = BsonDocumentWrapper.Create(scope);
return this;
}

Expand All @@ -337,7 +325,7 @@ IMongoScope scope
public MapReduceOptionsBuilder SetSortOrder(
IMongoSortBy sortBy
) {
document["sort"] = BsonDocument.Wrap(sortBy);
document["sort"] = BsonDocumentWrapper.Create(sortBy);
return this;
}

Expand Down
12 changes: 0 additions & 12 deletions Driver/Builders/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using MongoDB.Bson;
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Driver.Wrappers;

namespace MongoDB.Driver.Builders {
/// <summary>
Expand Down Expand Up @@ -457,17 +456,6 @@ double upperRightY
) {
return new QueryConditionList(name).WithinRectangle(lowerLeftX, lowerLeftY, upperRightX, upperRightY);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoQuery is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="query">The wrapped object.</param>
/// <returns>A QueryWrapper.</returns>
public static IMongoQuery Wrap(
object query
) {
return QueryWrapper.Create(query);
}
#endregion
}

Expand Down
12 changes: 0 additions & 12 deletions Driver/Builders/SortByBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using MongoDB.Bson.IO;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;

namespace MongoDB.Driver.Builders {
/// <summary>
Expand Down Expand Up @@ -60,17 +59,6 @@ params string[] keys
) {
return new SortByBuilder().Descending(keys);
}

/// <summary>
/// Wraps an object so that it can be used where an IMongoSortBy is expected (the wrapped object is expected to serialize properly).
/// </summary>
/// <param name="sortBy">The wrapped object.</param>
/// <returns>A SortByWrapper.</returns>
public static IMongoSortBy Wrap(
object sortBy
) {
return SortByWrapper.Create(sortBy);
}
#endregion
}

Expand Down
Loading

0 comments on commit 1944480

Please sign in to comment.