Skip to content

Commit ae4adc4

Browse files
authored
CSHARP-5226: Remove non-RenderArgs Render overloads (#1417)
1 parent 7dd4f76 commit ae4adc4

20 files changed

+17
-314
lines changed

src/MongoDB.Driver/AggregateExpressionDefinition.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,6 @@ public static implicit operator AggregateExpressionDefinition<TSource, TResult>(
6868
}
6969
#endregion
7070

71-
/// <summary>
72-
/// Renders the aggregation expression.
73-
/// </summary>
74-
/// <param name="sourceSerializer">The source serializer.</param>
75-
/// <param name="serializerRegistry">The serializer registry.</param>
76-
/// <returns>The rendered aggregation expression.</returns>
77-
[Obsolete("Use Render(RenderArgs<TSource> args) overload instead.")]
78-
public virtual BsonValue Render(IBsonSerializer<TSource> sourceSerializer, IBsonSerializerRegistry serializerRegistry)
79-
{
80-
return Render(new(sourceSerializer, serializerRegistry));
81-
}
82-
8371
/// <summary>
8472
/// Renders the aggregation expression to a <see cref="BsonValue"/>.
8573
/// </summary>

src/MongoDB.Driver/AggregateFacet.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,18 +72,6 @@ protected AggregateFacet(string name)
7272
/// </summary>
7373
public abstract Type OutputType { get; }
7474

75-
/// <summary>
76-
/// Renders the facet pipeline.
77-
/// </summary>
78-
/// <param name="inputSerializer">The input serializer.</param>
79-
/// <param name="serializerRegistry">The serializer registry.</param>
80-
/// <returns>The rendered pipeline.</returns>
81-
[Obsolete("Use Render(RenderArgs<TInput> args) overload instead.")]
82-
public virtual BsonArray RenderPipeline(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry)
83-
{
84-
return RenderPipeline(new(inputSerializer, serializerRegistry));
85-
}
86-
8775
/// <summary>
8876
/// Renders the facet pipeline.
8977
/// </summary>

src/MongoDB.Driver/FieldDefinition.cs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,6 @@ public IBsonSerializer<TField> ValueSerializer
135135
/// <typeparam name="TDocument">The type of the document.</typeparam>
136136
public abstract class FieldDefinition<TDocument>
137137
{
138-
/// <summary>
139-
/// Renders the field to a <see cref="RenderedFieldDefinition"/>.
140-
/// </summary>
141-
/// <param name="documentSerializer">The document serializer.</param>
142-
/// <param name="serializerRegistry">The serializer registry.</param>
143-
/// <returns>A <see cref="RenderedFieldDefinition"/>.</returns>
144-
[Obsolete("Use Render(RenderArgs<TDocument> args) overload instead.")]
145-
public virtual RenderedFieldDefinition Render(IBsonSerializer<TDocument> documentSerializer, IBsonSerializerRegistry serializerRegistry)
146-
{
147-
return Render(new(documentSerializer, serializerRegistry));
148-
}
149-
150138
/// <summary>
151139
/// Renders the field to a <see cref="RenderedFieldDefinition"/>.
152140
/// </summary>
@@ -179,34 +167,6 @@ public static implicit operator FieldDefinition<TDocument>(string fieldName)
179167
/// <typeparam name="TField">The type of the field.</typeparam>
180168
public abstract class FieldDefinition<TDocument, TField>
181169
{
182-
/// <summary>
183-
/// Renders the field to a <see cref="RenderedFieldDefinition{TField}"/>.
184-
/// </summary>
185-
/// <param name="documentSerializer">The document serializer.</param>
186-
/// <param name="serializerRegistry">The serializer registry.</param>
187-
/// <param name="allowScalarValueForArrayField">Whether a scalar value is allowed for an array field.</param>
188-
/// <returns>A <see cref="RenderedFieldDefinition{TField}"/>.</returns>
189-
[Obsolete("Use Render(RenderArgs<TDocument> args) overload instead.")]
190-
public virtual RenderedFieldDefinition<TField> Render(
191-
IBsonSerializer<TDocument> documentSerializer,
192-
IBsonSerializerRegistry serializerRegistry,
193-
bool allowScalarValueForArrayField)
194-
{
195-
return Render(new(documentSerializer, serializerRegistry)); // ignore allowScalarValueForArrayField if not overridden by subclass
196-
}
197-
198-
/// <summary>
199-
/// Renders the field to a <see cref="RenderedFieldDefinition{TField}"/>.
200-
/// </summary>
201-
/// <param name="documentSerializer">The document serializer.</param>
202-
/// <param name="serializerRegistry">The serializer registry.</param>
203-
/// <returns>A <see cref="RenderedFieldDefinition{TField}"/>.</returns>
204-
[Obsolete("Use Render(RenderArgs<TDocument> args) overload instead.")]
205-
public virtual RenderedFieldDefinition<TField> Render(IBsonSerializer<TDocument> documentSerializer, IBsonSerializerRegistry serializerRegistry)
206-
{
207-
return Render(new(documentSerializer, serializerRegistry));
208-
}
209-
210170
/// <summary>
211171
/// Renders the field to a <see cref="RenderedFieldDefinition{TField}"/>.
212172
/// </summary>

src/MongoDB.Driver/FilterDefinition.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
using System;
1717
using System.Linq.Expressions;
1818
using MongoDB.Bson;
19-
using MongoDB.Bson.Serialization;
2019
using MongoDB.Driver.Core.Misc;
2120
using MongoDB.Driver.Linq;
2221

@@ -38,18 +37,6 @@ public static FilterDefinition<TDocument> Empty
3837
get { return __empty; }
3938
}
4039

41-
/// <summary>
42-
/// Renders the filter to a <see cref="BsonDocument"/>.
43-
/// </summary>
44-
/// <param name="documentSerializer">The document serializer.</param>
45-
/// <param name="serializerRegistry">The serializer registry.</param>
46-
/// <returns>A <see cref="BsonDocument"/>.</returns>
47-
[Obsolete("Use Render(RenderArgs<TDocument> args) overload instead.")]
48-
public virtual BsonDocument Render(IBsonSerializer<TDocument> documentSerializer, IBsonSerializerRegistry serializerRegistry)
49-
{
50-
return Render(new(documentSerializer, serializerRegistry));
51-
}
52-
5340
/// <summary>
5441
/// Renders the filter to a <see cref="BsonDocument"/>.
5542
/// </summary>

src/MongoDB.Driver/IndexKeysDefinition.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
using System;
1717
using MongoDB.Bson;
18-
using MongoDB.Bson.Serialization;
1918
using MongoDB.Driver.Core.Misc;
2019

2120
namespace MongoDB.Driver
@@ -26,18 +25,6 @@ namespace MongoDB.Driver
2625
/// <typeparam name="TDocument">The type of the document.</typeparam>
2726
public abstract class IndexKeysDefinition<TDocument>
2827
{
29-
/// <summary>
30-
/// Renders the index keys definition to a <see cref="BsonDocument"/>.
31-
/// </summary>
32-
/// <param name="documentSerializer">The document serializer.</param>
33-
/// <param name="serializerRegistry">The serializer registry.</param>
34-
/// <returns>A <see cref="BsonDocument"/>.</returns>
35-
[Obsolete("Use Render(RenderArgs<TDocument> args) overload instead.")]
36-
public virtual BsonDocument Render(IBsonSerializer<TDocument> documentSerializer, IBsonSerializerRegistry serializerRegistry)
37-
{
38-
return Render(documentSerializer, serializerRegistry);
39-
}
40-
4128
/// <summary>
4229
/// Renders the index keys definition to a <see cref="BsonDocument"/>.
4330
/// </summary>

src/MongoDB.Driver/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/InjectMethodToFilterTranslator.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*/
1515

1616
using System.Linq.Expressions;
17+
using System.Reflection;
1718
using MongoDB.Bson;
1819
using MongoDB.Bson.Serialization;
1920
using MongoDB.Driver.Linq.Linq3Implementation.Ast.Filters;
@@ -25,6 +26,13 @@ namespace MongoDB.Driver.Linq.Linq3Implementation.Translators.ExpressionToFilter
2526
{
2627
internal static class InjectMethodToFilterTranslator
2728
{
29+
private readonly static MethodInfo __renderFilterMethodInfo;
30+
31+
static InjectMethodToFilterTranslator()
32+
{
33+
__renderFilterMethodInfo = typeof(InjectMethodToFilterTranslator).GetMethod(nameof(RenderFilter), BindingFlags.NonPublic | BindingFlags.Static);
34+
}
35+
2836
// public static methods
2937
public static AstFilter Translate(TranslationContext context, MethodCallExpression expression)
3038
{
@@ -37,19 +45,21 @@ public static AstFilter Translate(TranslationContext context, MethodCallExpressi
3745
var filterDefinition = filterExpression.GetConstantValue<object>(expression);
3846
var filterDefinitionType = filterDefinition.GetType(); // we KNOW it's a FilterDefinition<TDocument> because of the Inject method signature
3947
var documentType = filterDefinitionType.GetGenericArguments()[0];
48+
4049
var serializerRegistry = BsonSerializer.SerializerRegistry;
4150
var documentSerializer = serializerRegistry.GetSerializer(documentType); // TODO: is this the right serializer?
42-
var renderMethodArgumentTypes = new[]
43-
{
44-
typeof(IBsonSerializer<>).MakeGenericType(documentType),
45-
typeof(IBsonSerializerRegistry)
46-
};
47-
var renderMethod = filterDefinitionType.GetMethod("Render", renderMethodArgumentTypes);
48-
var renderedFilter = (BsonDocument)renderMethod.Invoke(filterDefinition, new object[] { documentSerializer, serializerRegistry });
51+
52+
var renderFilterMethod = __renderFilterMethodInfo.MakeGenericMethod(documentType);
53+
var renderedFilter = (BsonDocument)renderFilterMethod.Invoke(null, new[] { filterDefinition, documentSerializer, serializerRegistry });
54+
4955
return AstFilter.Raw(renderedFilter);
5056
}
5157

5258
throw new ExpressionNotSupportedException(expression);
5359
}
60+
61+
// private static methods
62+
private static BsonDocument RenderFilter<TDocument>(FilterDefinition<TDocument> filterDefinition, IBsonSerializer<TDocument> documentSerializer, IBsonSerializerRegistry serializerRegistry) =>
63+
filterDefinition.Render(new(documentSerializer, serializerRegistry));
5464
}
5565
}

src/MongoDB.Driver/PipelineDefinition.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ public abstract class PipelineDefinition<TInput, TOutput>
7878
/// </summary>
7979
public abstract IEnumerable<IPipelineStageDefinition> Stages { get; }
8080

81-
/// <summary>
82-
/// Renders the pipeline.
83-
/// </summary>
84-
/// <param name="inputSerializer">The input serializer.</param>
85-
/// <param name="serializerRegistry">The serializer registry.</param>
86-
/// <returns>A <see cref="RenderedPipelineDefinition{TOutput}"/></returns>
87-
[Obsolete("Use Render(RenderArgs<TInput> args) overload instead.")]
88-
public virtual RenderedPipelineDefinition<TOutput> Render(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry) =>
89-
Render(new (inputSerializer, serializerRegistry));
90-
9181
/// <summary>
9282
/// Renders the pipeline.
9383
/// </summary>

src/MongoDB.Driver/PipelineStageDefinition.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,6 @@ public Type OutputType
183183
get { return typeof(TOutput); }
184184
}
185185

186-
/// <summary>
187-
/// Renders the specified document serializer.
188-
/// </summary>
189-
/// <param name="inputSerializer">The input serializer.</param>
190-
/// <param name="serializerRegistry">The serializer registry.</param>
191-
/// <returns>A <see cref="RenderedPipelineStageDefinition{TOutput}" /></returns>
192-
[Obsolete("Use Render(RenderArgs<TInput> args) overload instead.")]
193-
public RenderedPipelineStageDefinition<TOutput> Render(IBsonSerializer<TInput> inputSerializer, IBsonSerializerRegistry serializerRegistry)
194-
{
195-
return Render(new RenderArgs<TInput>(inputSerializer, serializerRegistry));
196-
}
197-
198186
/// <summary>
199187
/// Renders the specified document serializer.
200188
/// </summary>

src/MongoDB.Driver/ProjectionDefinition.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,6 @@ public IBsonSerializer<TProjection> ProjectionSerializer
6565
/// <typeparam name="TSource">The type of the source.</typeparam>
6666
public abstract class ProjectionDefinition<TSource>
6767
{
68-
/// <summary>
69-
/// Renders the projection to a <see cref="RenderedProjectionDefinition{TProjection}"/>.
70-
/// </summary>
71-
/// <param name="sourceSerializer">The source serializer.</param>
72-
/// <param name="serializerRegistry">The serializer registry.</param>
73-
/// <returns>A <see cref="BsonDocument"/>.</returns>
74-
[Obsolete("Use Render(RenderArgs<TSource> args) overload instead.")]
75-
public virtual BsonDocument Render(IBsonSerializer<TSource> sourceSerializer, IBsonSerializerRegistry serializerRegistry)
76-
{
77-
return Render(new(sourceSerializer, serializerRegistry));
78-
}
79-
8068
/// <summary>
8169
/// Renders the projection to a <see cref="RenderedProjectionDefinition{TProjection}"/>.
8270
/// </summary>
@@ -126,18 +114,6 @@ public static implicit operator ProjectionDefinition<TSource>(string json)
126114
/// <typeparam name="TProjection">The type of the projection.</typeparam>
127115
public abstract class ProjectionDefinition<TSource, TProjection>
128116
{
129-
/// <summary>
130-
/// Renders the projection to a <see cref="RenderedProjectionDefinition{TProjection}"/>.
131-
/// </summary>
132-
/// <param name="sourceSerializer">The source serializer.</param>
133-
/// <param name="serializerRegistry">The serializer registry.</param>
134-
/// <returns>A <see cref="RenderedProjectionDefinition{TProjection}"/>.</returns>
135-
[Obsolete("Use Render(RenderArgs<TSource> args) overload instead.")]
136-
public virtual RenderedProjectionDefinition<TProjection> Render(IBsonSerializer<TSource> sourceSerializer, IBsonSerializerRegistry serializerRegistry)
137-
{
138-
return Render(new(sourceSerializer, serializerRegistry));
139-
}
140-
141117
/// <summary>
142118
/// Renders the projection to a <see cref="RenderedProjectionDefinition{TProjection}"/>.
143119
/// </summary>

src/MongoDB.Driver/Search/SearchDefinition.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
1716
using MongoDB.Bson;
1817
using MongoDB.Driver.Core.Misc;
1918

@@ -25,17 +24,6 @@ namespace MongoDB.Driver.Search
2524
/// <typeparam name="TDocument">The type of the document.</typeparam>
2625
public abstract class SearchDefinition<TDocument>
2726
{
28-
/// <summary>
29-
/// Renders the search definition to a <see cref="BsonDocument" />.
30-
/// </summary>
31-
/// <param name="renderContext">The render context.</param>
32-
/// <returns>
33-
/// A <see cref="BsonDocument" />.
34-
/// </returns>
35-
[Obsolete("Use Render(RenderArgs<TSource> args) overload instead.")]
36-
public virtual BsonDocument Render(SearchDefinitionRenderContext<TDocument> renderContext) =>
37-
Render(new RenderArgs<TDocument>(renderContext.DocumentSerializer, renderContext.SerializerRegistry, pathRenderArgs: new(renderContext.PathPrefix)));
38-
3927
/// <summary>
4028
/// Renders the search definition to a <see cref="BsonDocument" />.
4129
/// </summary>

0 commit comments

Comments
 (0)