Skip to content

Commit a014fe5

Browse files
author
rstam
committed
Changed IEnumerable<TMember> to IEnumerable<TValue> in typed builders. Renamed some variables to more closely align with their type names. Replaced a few <V> with <TMember>.
1 parent c1d7df7 commit a014fe5

13 files changed

+362
-365
lines changed

Driver/Builders/FieldsBuilder.cs

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Linq;
1919
using System.Linq.Expressions;
2020
using System.Text;
21+
2122
using MongoDB.Bson;
2223
using MongoDB.Bson.IO;
2324
using MongoDB.Bson.Serialization;
@@ -197,10 +198,8 @@ public static IMongoFields Null
197198
/// <summary>
198199
/// Adds one or more field names to be excluded from the results.
199200
/// </summary>
200-
/// <param name="memberExpressions">One or more field names.</param>
201-
/// <returns>
202-
/// The builder (so method calls can be chained).
203-
/// </returns>
201+
/// <param name="memberExpressions">The member expressions.</param>
202+
/// <returns>The builder (so method calls can be chained).</returns>
204203
public static FieldsBuilder<TDocument> Exclude(params Expression<Func<TDocument, object>>[] memberExpressions)
205204
{
206205
return new FieldsBuilder<TDocument>().Exclude(memberExpressions);
@@ -210,9 +209,7 @@ public static FieldsBuilder<TDocument> Exclude(params Expression<Func<TDocument,
210209
/// Adds one or more field names to be included in the results.
211210
/// </summary>
212211
/// <param name="memberExpressions">The member expressions.</param>
213-
/// <returns>
214-
/// The builder (so method calls can be chained).
215-
/// </returns>
212+
/// <returns>The builder (so method calls can be chained).</returns>
216213
public static FieldsBuilder<TDocument> Include(params Expression<Func<TDocument, object>>[] memberExpressions)
217214
{
218215
return new FieldsBuilder<TDocument>().Include(memberExpressions);
@@ -221,28 +218,24 @@ public static FieldsBuilder<TDocument> Include(params Expression<Func<TDocument,
221218
/// <summary>
222219
/// Adds a slice to be included in the results.
223220
/// </summary>
224-
/// <typeparam name="TMember">The type of the member.</typeparam>
221+
/// <typeparam name="TValue">The type of the enumerable member values.</typeparam>
225222
/// <param name="memberExpression">The member expression.</param>
226223
/// <param name="size">The size of the slice (negative sizes are taken from the end).</param>
227-
/// <returns>
228-
/// The builder (so method calls can be chained).
229-
/// </returns>
230-
public static FieldsBuilder<TDocument> Slice<TMember>(Expression<Func<TDocument, IEnumerable<TMember>>> memberExpression, int size)
224+
/// <returns>The builder (so method calls can be chained).</returns>
225+
public static FieldsBuilder<TDocument> Slice<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, int size)
231226
{
232227
return new FieldsBuilder<TDocument>().Slice(memberExpression, size);
233228
}
234229

235230
/// <summary>
236231
/// Adds a slice to be included in the results.
237232
/// </summary>
238-
/// <typeparam name="TMember">The type of the member.</typeparam>
233+
/// <typeparam name="TValue">The type of the enumerable member values.</typeparam>
239234
/// <param name="memberExpression">The member expression.</param>
240235
/// <param name="skip">The number of values to skip.</param>
241236
/// <param name="limit">The number of values to extract.</param>
242-
/// <returns>
243-
/// The builder (so method calls can be chained).
244-
/// </returns>
245-
public static FieldsBuilder<TDocument> Slice<TMember>(Expression<Func<TDocument, IEnumerable<TMember>>> memberExpression, int skip, int limit)
237+
/// <returns>The builder (so method calls can be chained).</returns>
238+
public static FieldsBuilder<TDocument> Slice<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, int skip, int limit)
246239
{
247240
return new FieldsBuilder<TDocument>().Slice(memberExpression, skip, limit);
248241
}
@@ -255,7 +248,8 @@ public static FieldsBuilder<TDocument> Slice<TMember>(Expression<Func<TDocument,
255248
[Serializable]
256249
public class FieldsBuilder<TDocument> : BuilderBase, IMongoFields
257250
{
258-
private readonly BsonSerializationInfoHelper _serializationHelper;
251+
// private fields
252+
private readonly BsonSerializationInfoHelper _serializationInfoHelper;
259253
private FieldsBuilder _fieldsBuilder;
260254

261255
// constructors
@@ -264,7 +258,7 @@ public class FieldsBuilder<TDocument> : BuilderBase, IMongoFields
264258
/// </summary>
265259
public FieldsBuilder()
266260
{
267-
_serializationHelper = new BsonSerializationInfoHelper();
261+
_serializationInfoHelper = new BsonSerializationInfoHelper();
268262
_fieldsBuilder = new FieldsBuilder();
269263
}
270264

@@ -273,13 +267,10 @@ public FieldsBuilder()
273267
/// Adds one or more field names to be excluded from the results.
274268
/// </summary>
275269
/// <param name="memberExpressions">The member expressions.</param>
276-
/// <returns>
277-
/// The builder (so method calls can be chained).
278-
/// </returns>
270+
/// <returns>The builder (so method calls can be chained).</returns>
279271
public FieldsBuilder<TDocument> Exclude(params Expression<Func<TDocument, object>>[] memberExpressions)
280272
{
281273
var elementNames = GetElementNames(memberExpressions);
282-
283274
_fieldsBuilder = _fieldsBuilder.Exclude(elementNames.ToArray());
284275
return this;
285276
}
@@ -288,61 +279,53 @@ public FieldsBuilder<TDocument> Exclude(params Expression<Func<TDocument, object
288279
/// Adds one or more field names to be included in the results.
289280
/// </summary>
290281
/// <param name="memberExpressions">The member expressions.</param>
291-
/// <returns>
292-
/// The builder (so method calls can be chained).
293-
/// </returns>
282+
/// <returns>The builder (so method calls can be chained).</returns>
294283
public FieldsBuilder<TDocument> Include(params Expression<Func<TDocument, object>>[] memberExpressions)
295284
{
296285
var elementNames = GetElementNames(memberExpressions);
297-
298286
_fieldsBuilder = _fieldsBuilder.Include(elementNames.ToArray());
299287
return this;
300288
}
301289

302290
/// <summary>
303291
/// Adds a slice to be included in the results.
304292
/// </summary>
305-
/// <typeparam name="TMember">The type of the member.</typeparam>
293+
/// <typeparam name="TValue">The type of the enumerable member values.</typeparam>
306294
/// <param name="memberExpression">The member expression.</param>
307295
/// <param name="size">The size of the slice (negative sizes are taken from the end).</param>
308-
/// <returns>
309-
/// The builder (so method calls can be chained).
310-
/// </returns>
311-
public FieldsBuilder<TDocument> Slice<TMember>(Expression<Func<TDocument, IEnumerable<TMember>>> memberExpression, int size)
296+
/// <returns>The builder (so method calls can be chained).</returns>
297+
public FieldsBuilder<TDocument> Slice<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, int size)
312298
{
313-
var info = _serializationHelper.GetSerializationInfo(memberExpression);
314-
_fieldsBuilder = _fieldsBuilder.Slice(info.ElementName, size);
299+
var serializationInfo = _serializationInfoHelper.GetSerializationInfo(memberExpression);
300+
_fieldsBuilder = _fieldsBuilder.Slice(serializationInfo.ElementName, size);
315301
return this;
316302
}
317303

318304
/// <summary>
319305
/// Adds a slice to be included in the results.
320306
/// </summary>
321-
/// <typeparam name="TMember">The type of the member.</typeparam>
307+
/// <typeparam name="TValue">The type of the enumerable member values.</typeparam>
322308
/// <param name="memberExpression">The member expression.</param>
323309
/// <param name="skip">The number of values to skip.</param>
324310
/// <param name="limit">The number of values to extract.</param>
325-
/// <returns>
326-
/// The builder (so method calls can be chained).
327-
/// </returns>
328-
public FieldsBuilder<TDocument> Slice<TMember>(Expression<Func<TDocument, IEnumerable<TMember>>> memberExpression, int skip, int limit)
311+
/// <returns>The builder (so method calls can be chained).</returns>
312+
public FieldsBuilder<TDocument> Slice<TValue>(Expression<Func<TDocument, IEnumerable<TValue>>> memberExpression, int skip, int limit)
329313
{
330-
var info = _serializationHelper.GetSerializationInfo(memberExpression);
331-
_fieldsBuilder = _fieldsBuilder.Slice(info.ElementName, skip, limit);
314+
var serializationInfo = _serializationInfoHelper.GetSerializationInfo(memberExpression);
315+
_fieldsBuilder = _fieldsBuilder.Slice(serializationInfo.ElementName, skip, limit);
332316
return this;
333317
}
334318

335319
/// <summary>
336320
/// Converts this object to a BsonDocument.
337321
/// </summary>
338-
/// <returns>
339-
/// A BsonDocument.
340-
/// </returns>
322+
/// <returns>A BsonDocument.</returns>
341323
public override BsonDocument ToBsonDocument()
342324
{
343325
return _fieldsBuilder.ToBsonDocument();
344326
}
345327

328+
// protected methods
346329
/// <summary>
347330
/// Serializes the result of the builder to a BsonWriter.
348331
/// </summary>
@@ -354,10 +337,11 @@ protected override void Serialize(BsonWriter bsonWriter, Type nominalType, IBson
354337
((IBsonSerializable)_fieldsBuilder).Serialize(bsonWriter, nominalType, options);
355338
}
356339

340+
// private methods
357341
private IEnumerable<string> GetElementNames(IEnumerable<Expression<Func<TDocument, object>>> memberExpressions)
358342
{
359343
var elementNames = memberExpressions
360-
.Select(x => _serializationHelper.GetSerializationInfo(x))
344+
.Select(x => _serializationInfoHelper.GetSerializationInfo(x))
361345
.Select(x => x.ElementName);
362346
return elementNames;
363347
}

Driver/Builders/GeoHaystackSearchOptionsBuilder.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Linq;
1919
using System.Linq.Expressions;
2020
using System.Text;
21+
2122
using MongoDB.Bson;
2223
using MongoDB.Bson.IO;
2324
using MongoDB.Bson.Serialization;
@@ -189,9 +190,7 @@ public static GeoHaystackSearchOptionsBuilder<TDocument> SetMaxDistance(double v
189190
/// <typeparam name="TMember">The member type.</typeparam>
190191
/// <param name="memberExpression">The member expression.</param>
191192
/// <param name="value">The value fo the additional field.</param>
192-
/// <returns>
193-
/// The builder (so method calls can be chained).
194-
/// </returns>
193+
/// <returns>The builder (so method calls can be chained).</returns>
195194
public static GeoHaystackSearchOptionsBuilder<TDocument> SetQuery<TMember>(Expression<Func<TDocument, TMember>> memberExpression, TMember value)
196195
{
197196
return new GeoHaystackSearchOptionsBuilder<TDocument>().SetQuery(memberExpression, value);
@@ -205,7 +204,8 @@ public static GeoHaystackSearchOptionsBuilder<TDocument> SetQuery<TMember>(Expre
205204
[Serializable]
206205
public class GeoHaystackSearchOptionsBuilder<TDocument> : BuilderBase, IMongoGeoHaystackSearchOptions
207206
{
208-
private readonly BsonSerializationInfoHelper _serializationHelper;
207+
// private fields
208+
private readonly BsonSerializationInfoHelper _serializationInfoHelper;
209209
private GeoHaystackSearchOptionsBuilder _geoHaystackBuilder;
210210

211211
// constructors
@@ -214,7 +214,7 @@ public class GeoHaystackSearchOptionsBuilder<TDocument> : BuilderBase, IMongoGeo
214214
/// </summary>
215215
public GeoHaystackSearchOptionsBuilder()
216216
{
217-
_serializationHelper = new BsonSerializationInfoHelper();
217+
_serializationInfoHelper = new BsonSerializationInfoHelper();
218218
_geoHaystackBuilder = new GeoHaystackSearchOptionsBuilder();
219219
}
220220

@@ -247,28 +247,25 @@ public GeoHaystackSearchOptionsBuilder<TDocument> SetMaxDistance(double value)
247247
/// <typeparam name="TMember">The type of the member.</typeparam>
248248
/// <param name="memberExpression">The member expression.</param>
249249
/// <param name="value">The value fo the additional field.</param>
250-
/// <returns>
251-
/// The builder (so method calls can be chained).
252-
/// </returns>
250+
/// <returns>The builder (so method calls can be chained).</returns>
253251
public GeoHaystackSearchOptionsBuilder<TDocument> SetQuery<TMember>(Expression<Func<TDocument, TMember>> memberExpression, TMember value)
254252
{
255-
var info = _serializationHelper.GetSerializationInfo(memberExpression);
256-
var serializedValue = _serializationHelper.SerializeValue(info, value);
257-
_geoHaystackBuilder = _geoHaystackBuilder.SetQuery(info.ElementName, serializedValue);
253+
var serializationInfo = _serializationInfoHelper.GetSerializationInfo(memberExpression);
254+
var serializedValue = _serializationInfoHelper.SerializeValue(serializationInfo, value);
255+
_geoHaystackBuilder = _geoHaystackBuilder.SetQuery(serializationInfo.ElementName, serializedValue);
258256
return this;
259257
}
260258

261259
/// <summary>
262260
/// Converts this object to a BsonDocument.
263261
/// </summary>
264-
/// <returns>
265-
/// A BsonDocument.
266-
/// </returns>
262+
/// <returns>A BsonDocument.</returns>
267263
public override BsonDocument ToBsonDocument()
268264
{
269265
return _geoHaystackBuilder.ToBsonDocument();
270266
}
271267

268+
// protected methods
272269
/// <summary>
273270
/// Serializes the result of the builder to a BsonWriter.
274271
/// </summary>
@@ -280,4 +277,4 @@ protected override void Serialize(BsonWriter bsonWriter, Type nominalType, IBson
280277
((IBsonSerializable)_geoHaystackBuilder).Serialize(bsonWriter, nominalType, options);
281278
}
282279
}
283-
}
280+
}

Driver/Builders/GroupByBuilder.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Linq;
1919
using System.Linq.Expressions;
2020
using System.Text;
21+
2122
using MongoDB.Bson;
2223
using MongoDB.Bson.IO;
2324
using MongoDB.Bson.Serialization;
@@ -61,6 +62,7 @@ public class GroupByBuilder : BuilderBase, IMongoGroupBy
6162
// private fields
6263
private BsonDocument _document;
6364

65+
// constructors
6466
/// <summary>
6567
/// Initializes a new instance of the <see cref="GroupByBuilder"/> class.
6668
/// </summary>
@@ -69,7 +71,6 @@ public GroupByBuilder()
6971
_document = new BsonDocument();
7072
}
7173

72-
// constructors
7374
/// <summary>
7475
/// Initializes a new instance of the GroupByBuilder class.
7576
/// </summary>
@@ -85,9 +86,7 @@ public GroupByBuilder(string[] names)
8586
/// Sets one or more key names.
8687
/// </summary>
8788
/// <param name="names">The names.</param>
88-
/// <returns>
89-
/// The builder (so method calls can be chained).
90-
/// </returns>
89+
/// <returns>The builder (so method calls can be chained).</returns>
9190
public GroupByBuilder Keys(params string[] names)
9291
{
9392
foreach (var name in names)
@@ -126,6 +125,7 @@ protected override void Serialize(BsonWriter bsonWriter, Type nominalType, IBson
126125
/// <typeparam name="TDocument">The type of the document.</typeparam>
127126
public static class GroupBy<TDocument>
128127
{
128+
// public static methods
129129
/// <summary>
130130
/// Sets one or more key names.
131131
/// </summary>
@@ -143,29 +143,30 @@ public static GroupByBuilder<TDocument> Keys(params Expression<Func<TDocument, o
143143
/// <typeparam name="TDocument">The type of the document.</typeparam>
144144
public class GroupByBuilder<TDocument> : BuilderBase, IMongoGroupBy
145145
{
146-
private readonly BsonSerializationInfoHelper _serializationHelper;
146+
// private fields
147+
private readonly BsonSerializationInfoHelper _serializationInfoHelper;
147148
private GroupByBuilder _groupByBuilder;
148149

150+
// constructors
149151
/// <summary>
150152
/// Initializes a new instance of the <see cref="GroupByBuilder&lt;TDocument&gt;"/> class.
151153
/// </summary>
152154
public GroupByBuilder()
153155
{
154-
_serializationHelper = new BsonSerializationInfoHelper();
156+
_serializationInfoHelper = new BsonSerializationInfoHelper();
155157
_groupByBuilder = new GroupByBuilder();
156158
}
157159

160+
// public methods
158161
/// <summary>
159162
/// Sets one or more key names.
160163
/// </summary>
161164
/// <param name="memberExpressions">One or more key names.</param>
162-
/// <returns>
163-
/// The builder (so method calls can be chained).
164-
/// </returns>
165+
/// <returns>The builder (so method calls can be chained).</returns>
165166
public GroupByBuilder<TDocument> Keys(params Expression<Func<TDocument, object>>[] memberExpressions)
166167
{
167168
var names = memberExpressions
168-
.Select(x => _serializationHelper.GetSerializationInfo(x))
169+
.Select(x => _serializationInfoHelper.GetSerializationInfo(x))
169170
.Select(x => x.ElementName);
170171

171172
_groupByBuilder = _groupByBuilder.Keys(names.ToArray());
@@ -175,14 +176,13 @@ public GroupByBuilder<TDocument> Keys(params Expression<Func<TDocument, object>>
175176
/// <summary>
176177
/// Converts this object to a BsonDocument.
177178
/// </summary>
178-
/// <returns>
179-
/// A BsonDocument.
180-
/// </returns>
179+
/// <returns>A BsonDocument.</returns>
181180
public override BsonDocument ToBsonDocument()
182181
{
183182
return _groupByBuilder.ToBsonDocument();
184183
}
185184

185+
// protected methods
186186
/// <summary>
187187
/// Serializes the result of the builder to a BsonWriter.
188188
/// </summary>
@@ -194,4 +194,4 @@ protected override void Serialize(BsonWriter bsonWriter, Type nominalType, IBson
194194
((IBsonSerializable)_groupByBuilder).Serialize(bsonWriter, nominalType, options);
195195
}
196196
}
197-
}
197+
}

0 commit comments

Comments
 (0)