-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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-4935: Linq3Implementation unable to handle interface as root #1419
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LINQ changes in this PR look fine to me.
The concern we had that has kept this on the back burner is whether the change to DiscriminatedInterfaceSerializer
would be backward breaking in any way.
@@ -96,7 +109,7 @@ public DiscriminatedInterfaceSerializer(IDiscriminatorConvention discriminatorCo | |||
|
|||
_interfaceType = typeof(TInterface); | |||
_discriminatorConvention = discriminatorConvention ?? BsonSerializer.LookupDiscriminatorConvention(typeof(TInterface)); | |||
_objectSerializer = BsonSerializer.LookupSerializer<object>(); | |||
_objectSerializer = objectSerializer ?? new ObjectSerializer(allowedTypes: type => typeof(TInterface).IsAssignableFrom(type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see any backward compatibility issues with this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a problem if someone registered their own object serializer for some reasons. Can we implement method like a WithAllowedTypes
on objectSerializer? So we lookup the same way as it was before - and then try to use this new method, similar to this:
var objectSerializer = BsonSerializer.LookupSerializer<object>();
if (objectSerializer is ObjectSerializer builtInSerializer)
{
objectSerializer = builtInSerializer.WithAllowedTypes(allowedTypes: type => typeof(TInterface).IsAssignableFrom(type));
}
@@ -96,7 +109,7 @@ public DiscriminatedInterfaceSerializer(IDiscriminatorConvention discriminatorCo | |||
|
|||
_interfaceType = typeof(TInterface); | |||
_discriminatorConvention = discriminatorConvention ?? BsonSerializer.LookupDiscriminatorConvention(typeof(TInterface)); | |||
_objectSerializer = BsonSerializer.LookupSerializer<object>(); | |||
_objectSerializer = objectSerializer ?? new ObjectSerializer(allowedTypes: type => typeof(TInterface).IsAssignableFrom(type)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a problem if someone registered their own object serializer for some reasons. Can we implement method like a WithAllowedTypes
on objectSerializer? So we lookup the same way as it was before - and then try to use this new method, similar to this:
var objectSerializer = BsonSerializer.LookupSerializer<object>();
if (objectSerializer is ObjectSerializer builtInSerializer)
{
objectSerializer = builtInSerializer.WithAllowedTypes(allowedTypes: type => typeof(TInterface).IsAssignableFrom(type));
}
No description provided.