Skip to content

Commit 2b37a1f

Browse files
authored
CSHARP-3977: Refactor GroupForLinq3 to return an explicit type. (#693)
1 parent ec4b2ce commit 2b37a1f

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System.Linq;
17+
18+
namespace MongoDB.Driver
19+
{
20+
/// <summary>
21+
/// Represents the return result from PipelineDefinitionBuilder.GroupForLinq3 method.
22+
/// </summary>
23+
/// <typeparam name="TInput">The type of the input documents.</typeparam>
24+
/// <typeparam name="TValue">The type of the values.</typeparam>
25+
/// <typeparam name="TOutput">The type of the output documents.</typeparam>
26+
public class GroupForLinq3Result<TInput, TValue, TOutput>
27+
{
28+
internal GroupForLinq3Result(PipelineStageDefinition<TInput, IGrouping<TValue, TInput>> groupStage, PipelineStageDefinition<IGrouping<TValue, TInput>, TOutput> projectStage)
29+
{
30+
GroupStage = groupStage;
31+
ProjectStage = projectStage;
32+
}
33+
34+
/// <summary>
35+
/// The resulting group stage.
36+
/// </summary>
37+
public PipelineStageDefinition<TInput, IGrouping<TValue, TInput>> GroupStage { get; }
38+
39+
/// <summary>
40+
/// The resulting project stage.
41+
/// </summary>
42+
public PipelineStageDefinition<IGrouping<TValue, TInput>, TOutput> ProjectStage { get; }
43+
44+
/// <summary>
45+
/// Deconstructs this class into its components.
46+
/// </summary>
47+
/// <param name="groupStage">The group stage.</param>
48+
/// <param name="projectStage">The project stage.</param>
49+
public void Deconstruct(
50+
out PipelineStageDefinition<TInput, IGrouping<TValue, TInput>> groupStage,
51+
out PipelineStageDefinition<IGrouping<TValue, TInput>, TOutput> projectStage)
52+
{
53+
groupStage = GroupStage;
54+
projectStage = ProjectStage;
55+
}
56+
}
57+
}

src/MongoDB.Driver/PipelineStageDefinitionBuilder.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,15 @@ public static PipelineStageDefinition<TInput, TOutput> Group<TInput, TValue, TOu
735735
/// <param name="translationOptions">The translation options.</param>
736736
/// <returns>The stage.</returns>
737737
/// <remarks>This method can only be used with LINQ3 but that can't be verified until Render is called.</remarks>
738-
public static (PipelineStageDefinition<TInput, IGrouping<TValue, TInput>> GroupStage, PipelineStageDefinition<IGrouping<TValue, TInput>, TOutput> ProjectStage) GroupForLinq3<TInput, TValue, TOutput>(
738+
public static GroupForLinq3Result<TInput, TValue, TOutput> GroupForLinq3<TInput, TValue, TOutput>(
739739
Expression<Func<TInput, TValue>> value,
740740
Expression<Func<IGrouping<TValue, TInput>, TOutput>> group,
741741
ExpressionTranslationOptions translationOptions = null)
742742
{
743743
Ensure.IsNotNull(value, nameof(value));
744744
Ensure.IsNotNull(group, nameof(group));
745745
var stages = new Linq.Linq3Implementation.GroupExpressionStageDefinitions<TInput, TValue, TOutput>(value, group);
746-
return (stages.GroupStage, stages.ProjectStage);
746+
return new GroupForLinq3Result<TInput, TValue, TOutput>(stages.GroupStage, stages.ProjectStage);
747747
}
748748

749749
/// <summary>

0 commit comments

Comments
 (0)