Skip to content

Commit b9ca291

Browse files
committed
Use TProjection instead of TResult when a projection is involved.
1 parent 7b487e5 commit b9ca291

15 files changed

+201
-201
lines changed

src/MongoDB.Driver/FindFluent.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020

2121
namespace MongoDB.Driver
2222
{
23-
internal class FindFluent<TDocument, TResult> : FindFluentBase<TDocument, TResult>
23+
internal class FindFluent<TDocument, TProjection> : FindFluentBase<TDocument, TProjection>
2424
{
2525
// fields
2626
private readonly IMongoCollection<TDocument> _collection;
2727
private FilterDefinition<TDocument> _filter;
28-
private readonly FindOptions<TDocument, TResult> _options;
28+
private readonly FindOptions<TDocument, TProjection> _options;
2929

3030
// constructors
31-
public FindFluent(IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, FindOptions<TDocument, TResult> options)
31+
public FindFluent(IMongoCollection<TDocument> collection, FilterDefinition<TDocument> filter, FindOptions<TDocument, TProjection> options)
3232
{
3333
_collection = Ensure.IsNotNull(collection, "collection");
3434
_filter = Ensure.IsNotNull(filter, "filter");
@@ -42,7 +42,7 @@ public override FilterDefinition<TDocument> Filter
4242
set { _filter = Ensure.IsNotNull(value, "value"); }
4343
}
4444

45-
public override FindOptions<TDocument, TResult> Options
45+
public override FindOptions<TDocument, TProjection> Options
4646
{
4747
get { return _options; }
4848
}
@@ -63,15 +63,15 @@ public override Task<long> CountAsync(CancellationToken cancellationToken)
6363
return _collection.CountAsync(_filter, options, cancellationToken);
6464
}
6565

66-
public override IFindFluent<TDocument, TResult> Limit(int? limit)
66+
public override IFindFluent<TDocument, TProjection> Limit(int? limit)
6767
{
6868
_options.Limit = limit;
6969
return this;
7070
}
7171

72-
public override IFindFluent<TDocument, TNewResult> Project<TNewResult>(ProjectionDefinition<TDocument, TNewResult> projection)
72+
public override IFindFluent<TDocument, TNewProjection> Project<TNewProjection>(ProjectionDefinition<TDocument, TNewProjection> projection)
7373
{
74-
var newOptions = new FindOptions<TDocument, TNewResult>
74+
var newOptions = new FindOptions<TDocument, TNewProjection>
7575
{
7676
AllowPartialResults = _options.AllowPartialResults,
7777
BatchSize = _options.BatchSize,
@@ -85,22 +85,22 @@ public override IFindFluent<TDocument, TNewResult> Project<TNewResult>(Projectio
8585
Skip = _options.Skip,
8686
Sort = _options.Sort,
8787
};
88-
return new FindFluent<TDocument, TNewResult>(_collection, _filter, newOptions);
88+
return new FindFluent<TDocument, TNewProjection>(_collection, _filter, newOptions);
8989
}
9090

91-
public override IFindFluent<TDocument, TResult> Skip(int? skip)
91+
public override IFindFluent<TDocument, TProjection> Skip(int? skip)
9292
{
9393
_options.Skip = skip;
9494
return this;
9595
}
9696

97-
public override IFindFluent<TDocument, TResult> Sort(SortDefinition<TDocument> sort)
97+
public override IFindFluent<TDocument, TProjection> Sort(SortDefinition<TDocument> sort)
9898
{
9999
_options.Sort = sort;
100100
return this;
101101
}
102102

103-
public override Task<IAsyncCursor<TResult>> ToCursorAsync(CancellationToken cancellationToken = default(CancellationToken))
103+
public override Task<IAsyncCursor<TProjection>> ToCursorAsync(CancellationToken cancellationToken = default(CancellationToken))
104104
{
105105
return _collection.FindAsync(_filter, _options, cancellationToken);
106106
}

src/MongoDB.Driver/FindFluentBase.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,34 +19,34 @@
1919
namespace MongoDB.Driver
2020
{
2121
/// <summary>
22-
/// Base class for implementors of <see cref="IFindFluent{TDocument, TResult}" />.
22+
/// Base class for implementors of <see cref="IFindFluent{TDocument, TProjection}" />.
2323
/// </summary>
2424
/// <typeparam name="TDocument">The type of the document.</typeparam>
25-
/// <typeparam name="TResult">The type of the result.</typeparam>
26-
public abstract class FindFluentBase<TDocument, TResult> : IOrderedFindFluent<TDocument, TResult>
25+
/// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
26+
public abstract class FindFluentBase<TDocument, TProjection> : IOrderedFindFluent<TDocument, TProjection>
2727
{
2828
/// <inheritdoc />
2929
public abstract FilterDefinition<TDocument> Filter { get; set; }
3030

3131
/// <inheritdoc />
32-
public abstract FindOptions<TDocument, TResult> Options { get; }
32+
public abstract FindOptions<TDocument, TProjection> Options { get; }
3333

3434
/// <inheritdoc />
3535
public abstract Task<long> CountAsync(CancellationToken cancellationToken = default(CancellationToken));
3636

3737
/// <inheritdoc />
38-
public abstract IFindFluent<TDocument, TResult> Limit(int? limit);
38+
public abstract IFindFluent<TDocument, TProjection> Limit(int? limit);
3939

4040
/// <inheritdoc />
41-
public abstract IFindFluent<TDocument, TNewResult> Project<TNewResult>(ProjectionDefinition<TDocument, TNewResult> projection);
41+
public abstract IFindFluent<TDocument, TNewProjection> Project<TNewProjection>(ProjectionDefinition<TDocument, TNewProjection> projection);
4242

4343
/// <inheritdoc />
44-
public abstract IFindFluent<TDocument, TResult> Skip(int? skip);
44+
public abstract IFindFluent<TDocument, TProjection> Skip(int? skip);
4545

4646
/// <inheritdoc />
47-
public abstract IFindFluent<TDocument, TResult> Sort(SortDefinition<TDocument> sort);
47+
public abstract IFindFluent<TDocument, TProjection> Sort(SortDefinition<TDocument> sort);
4848

4949
/// <inheritdoc />
50-
public abstract Task<IAsyncCursor<TResult>> ToCursorAsync(CancellationToken cancellationToken);
50+
public abstract Task<IAsyncCursor<TProjection>> ToCursorAsync(CancellationToken cancellationToken);
5151
}
5252
}

src/MongoDB.Driver/FindOneAndDeleteOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ namespace MongoDB.Driver
2626
/// Options for a findAndModify command to delete an object.
2727
/// </summary>
2828
/// <typeparam name="TDocument">The type of the document.</typeparam>
29-
/// <typeparam name="TResult">The type of the result.</typeparam>
30-
public class FindOneAndDeleteOptions<TDocument, TResult>
29+
/// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
30+
public class FindOneAndDeleteOptions<TDocument, TProjection>
3131
{
3232
// fields
3333
private TimeSpan? _maxTime;
34-
private ProjectionDefinition<TDocument, TResult> _projection;
34+
private ProjectionDefinition<TDocument, TProjection> _projection;
3535
private SortDefinition<TDocument> _sort;
3636

3737
// properties
@@ -47,7 +47,7 @@ public TimeSpan? MaxTime
4747
/// <summary>
4848
/// Gets or sets the projection.
4949
/// </summary>
50-
public ProjectionDefinition<TDocument, TResult> Projection
50+
public ProjectionDefinition<TDocument, TProjection> Projection
5151
{
5252
get { return _projection; }
5353
set { _projection = value; }

src/MongoDB.Driver/FindOneAndReplaceOptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ namespace MongoDB.Driver
2626
/// Options for a findAndModify command to replace an object.
2727
/// </summary>
2828
/// <typeparam name="TDocument">The type of the document.</typeparam>
29-
/// <typeparam name="TResult">The type of the result.</typeparam>
30-
public class FindOneAndReplaceOptions<TDocument, TResult>
29+
/// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
30+
public class FindOneAndReplaceOptions<TDocument, TProjection>
3131
{
3232
// fields
3333
private bool _isUpsert;
3434
private TimeSpan? _maxTime;
35-
private ProjectionDefinition<TDocument, TResult> _projection;
35+
private ProjectionDefinition<TDocument, TProjection> _projection;
3636
private ReturnDocument _returnDocument;
3737
private SortDefinition<TDocument> _sort;
3838

3939
// constructors
4040
/// <summary>
41-
/// Initializes a new instance of the <see cref="FindOneAndReplaceOptions{TDocument, TResult}"/> class.
41+
/// Initializes a new instance of the <see cref="FindOneAndReplaceOptions{TDocument, TProjection}"/> class.
4242
/// </summary>
4343
public FindOneAndReplaceOptions()
4444
{
@@ -67,7 +67,7 @@ public TimeSpan? MaxTime
6767
/// <summary>
6868
/// Gets or sets the projection.
6969
/// </summary>
70-
public ProjectionDefinition<TDocument, TResult> Projection
70+
public ProjectionDefinition<TDocument, TProjection> Projection
7171
{
7272
get { return _projection; }
7373
set { _projection = value; }

src/MongoDB.Driver/FindOneAndUpdateOptions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,19 @@ namespace MongoDB.Driver
2626
/// Options for a findAndModify command to update an object.
2727
/// </summary>
2828
/// <typeparam name="TDocument">The type of the document.</typeparam>
29-
/// <typeparam name="TResult">The type of the result.</typeparam>
30-
public class FindOneAndUpdateOptions<TDocument, TResult>
29+
/// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
30+
public class FindOneAndUpdateOptions<TDocument, TProjection>
3131
{
3232
// fields
3333
private bool _isUpsert;
3434
private TimeSpan? _maxTime;
35-
private ProjectionDefinition<TDocument, TResult> _projection;
35+
private ProjectionDefinition<TDocument, TProjection> _projection;
3636
private ReturnDocument _returnDocument;
3737
private SortDefinition<TDocument> _sort;
3838

3939
// constructors
4040
/// <summary>
41-
/// Initializes a new instance of the <see cref="FindOneAndUpdateOptions{TDocument, TResult}"/> class.
41+
/// Initializes a new instance of the <see cref="FindOneAndUpdateOptions{TDocument, TProjection}"/> class.
4242
/// </summary>
4343
public FindOneAndUpdateOptions()
4444
{
@@ -67,7 +67,7 @@ public TimeSpan? MaxTime
6767
/// <summary>
6868
/// Gets or sets the projection.
6969
/// </summary>
70-
public ProjectionDefinition<TDocument, TResult> Projection
70+
public ProjectionDefinition<TDocument, TProjection> Projection
7171
{
7272
get { return _projection; }
7373
set { _projection = value; }

src/MongoDB.Driver/FindOptions.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ public class FindOptions : FindOptionsBase
106106
/// Options for finding documents.
107107
/// </summary>
108108
/// <typeparam name="TDocument">The type of the document.</typeparam>
109-
/// <typeparam name="TResult">The type of the result.</typeparam>
110-
public class FindOptions<TDocument, TResult> : FindOptionsBase
109+
/// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
110+
public class FindOptions<TDocument, TProjection> : FindOptionsBase
111111
{
112112
// fields
113113
private int? _limit;
114-
private ProjectionDefinition<TDocument, TResult> _projection;
114+
private ProjectionDefinition<TDocument, TProjection> _projection;
115115
private int? _skip;
116116
private SortDefinition<TDocument> _sort;
117117

@@ -128,7 +128,7 @@ public int? Limit
128128
/// <summary>
129129
/// Gets or sets the projection.
130130
/// </summary>
131-
public ProjectionDefinition<TDocument, TResult> Projection
131+
public ProjectionDefinition<TDocument, TProjection> Projection
132132
{
133133
get { return _projection; }
134134
set { _projection = value; }

src/MongoDB.Driver/IFindFluent.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ namespace MongoDB.Driver
2626
/// </summary>
2727
/// <remarks>
2828
/// This interface is not guaranteed to remain stable. Implementors should use
29-
/// <see cref="FindFluentBase{TDocument, TResult}" />.
29+
/// <see cref="FindFluentBase{TDocument, TProjection}" />.
3030
/// </remarks>
3131
/// <typeparam name="TDocument">The type of the document.</typeparam>
32-
/// <typeparam name="TResult">The type of the result.</typeparam>
33-
public interface IFindFluent<TDocument, TResult> : IAsyncCursorSource<TResult>
32+
/// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
33+
public interface IFindFluent<TDocument, TProjection> : IAsyncCursorSource<TProjection>
3434
{
3535
/// <summary>
3636
/// Gets or sets the filter.
@@ -40,7 +40,7 @@ public interface IFindFluent<TDocument, TResult> : IAsyncCursorSource<TResult>
4040
/// <summary>
4141
/// Gets the options.
4242
/// </summary>
43-
FindOptions<TDocument, TResult> Options { get; }
43+
FindOptions<TDocument, TProjection> Options { get; }
4444

4545
/// <summary>
4646
/// Counts the number of documents.
@@ -54,37 +54,37 @@ public interface IFindFluent<TDocument, TResult> : IAsyncCursorSource<TResult>
5454
/// </summary>
5555
/// <param name="limit">The limit.</param>
5656
/// <returns>The fluent find interface.</returns>
57-
IFindFluent<TDocument, TResult> Limit(int? limit);
57+
IFindFluent<TDocument, TProjection> Limit(int? limit);
5858

5959
/// <summary>
6060
/// Projects the the result.
6161
/// </summary>
62-
/// <typeparam name="TNewResult">The type of the result.</typeparam>
62+
/// <typeparam name="TNewProjection">The type of the projection.</typeparam>
6363
/// <param name="projection">The projection.</param>
6464
/// <returns>The fluent find interface.</returns>
65-
IFindFluent<TDocument, TNewResult> Project<TNewResult>(ProjectionDefinition<TDocument, TNewResult> projection);
65+
IFindFluent<TDocument, TNewProjection> Project<TNewProjection>(ProjectionDefinition<TDocument, TNewProjection> projection);
6666

6767
/// <summary>
6868
/// Skips the the specified number of documents.
6969
/// </summary>
7070
/// <param name="skip">The skip.</param>
7171
/// <returns>The fluent find interface.</returns>
72-
IFindFluent<TDocument, TResult> Skip(int? skip);
72+
IFindFluent<TDocument, TProjection> Skip(int? skip);
7373

7474
/// <summary>
7575
/// Sorts the the documents.
7676
/// </summary>
7777
/// <param name="sort">The sort.</param>
7878
/// <returns>The fluent find interface.</returns>
79-
IFindFluent<TDocument, TResult> Sort(SortDefinition<TDocument> sort);
79+
IFindFluent<TDocument, TProjection> Sort(SortDefinition<TDocument> sort);
8080
}
8181

8282
/// <summary>
8383
/// Fluent interface for find.
8484
/// </summary>
8585
/// <typeparam name="TDocument">The type of the document.</typeparam>
86-
/// <typeparam name="TResult">The type of the result.</typeparam>
87-
public interface IOrderedFindFluent<TDocument, TResult> : IFindFluent<TDocument, TResult>
86+
/// <typeparam name="TProjection">The type of the projection (same as TDocument if there is no projection).</typeparam>
87+
public interface IOrderedFindFluent<TDocument, TProjection> : IFindFluent<TDocument, TProjection>
8888
{
8989
}
9090
}

0 commit comments

Comments
 (0)