Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSHARP-4955: Add Render overload with RenderArgs #1278

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

BorisDog
Copy link
Contributor

  • Added support for records (IsExternalInit.cs)
  • Added RenderArgs overloads
  • Removed RenderForFind and FilterDefinitionRenderContext workarounds
  • Added obsoletion attributes for older Render methods

@BorisDog BorisDog requested a review from a team as a code owner February 29, 2024 21:40
@BorisDog BorisDog requested review from sanych-sun and rstam and removed request for a team February 29, 2024 21:40
namespace System.Runtime.CompilerServices
{
[EditorBrowsable(EditorBrowsableState.Never)]
internal class IsExternalInit { }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed for records support.

{ "limit", limit },
{ "numCandidates", options?.NumberOfCandidates ?? limit * 10 },
{ "index", options?.IndexName ?? "default" },
{ "filter", () => RenderFilter(s, sr, linqProvider), options?.Filter != null },
{ "filter", () => options.Filter.Render(renderArgs with { RenderDollarForm = true }), options?.Filter != null },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This replaces the workaround with FilterDefinitionRenderContext, which is removed now.

var renderedField = _field.Render(sourceSerializer, serializerRegistry, linqProvider);
var sliceArgs = argsRenderer(renderedField.FieldName);
var renderedField = _field.Render(renderArgs);
var sliceArgs = renderArgs.IsAggregateMode ? RenderArgs(renderedField.FieldName) : RenderArgsForFind(renderedField.FieldName);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IsAggregateMode replaces RenderForFind pattern.

Copy link
Contributor

@rstam rstam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with a quick review and some initial questions.

@@ -0,0 +1,103 @@
using MongoDB.Bson.Serialization;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add copyright.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Done.

bool renderDollarForm = default,
bool isAggregateMode = true)
{
DocumentSerializer = documentSerializer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure.IsNotNull?

/// <summary>
/// Gets the document serializer.
/// </summary>
public IBsonSerializer<TDocument> DocumentSerializer { get => _documentSerializer; init => _documentSerializer = value; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure.IsNotNull in init?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, that was initial implementation. But in case of ArrayFilterDefinition null is passed for serializer.
But I think we can make an exception for ArrayFilterDefinition and not use RenderArgs there.
Added null check.

/// or resolves <c>IBsonSerializer{T}</c> from <see cref="SerializerRegistry"/>.
/// </summary>
public IBsonSerializer<T> GetSerializer<T>() =>
DocumentSerializer as IBsonSerializer<T> ?? SerializerRegistry.GetSerializer<T>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous. There is no guarantee that the serializer in the registry is the right one for THIS builder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a convenience method, that replaces same functionality in lots of places.

/// <returns>
/// A new RenderArgs{TNewDocument} instance.
/// </returns>
public RenderArgs<TNewDocument> WithSerializer<TNewDocument>(IBsonSerializer<TNewDocument> serializer) =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I didn't realize why you weren't using the language support for with.

Maybe emphasize in the doc comments that we aren't just changing the serializer but most likely changing the TDocument type also.

Maybe even rename this method to something like WithNewDocumentType?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, renamed to WithNewDocumentType.

@BorisDog BorisDog requested a review from rstam March 18, 2024 20:15
@JamesKovacs JamesKovacs removed the request for review from rstam April 3, 2024 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants