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-3315: Implement Equals for serializers. #1281

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

Conversation

rstam
Copy link
Contributor

@rstam rstam commented Mar 5, 2024

No description provided.

@rstam rstam requested a review from JamesKovacs March 5, 2024 16:26
@rstam rstam requested a review from a team as a code owner March 5, 2024 16:26
@rstam rstam removed request for a team and JamesKovacs March 14, 2024 21:58
@rstam
Copy link
Contributor Author

rstam commented May 9, 2024

Not ready for review yet. The new commits are just to back up work in progress in case something happens to my laptop.

Copy link
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

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

Partial review. About ~50% of the tests remain to be reviewed.

</ItemGroup>

<ItemGroup>
<Folder Include="Shared\" />
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this folder include is not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how it got here. Don't think I edited this file manually.

object.Equals(_memberInfo, other._memberInfo) &&
_order.Equals(other._order) &&
object.Equals(_serializer, other._serializer) &&
object.Equals(_shouldSerializeMethod, other._shouldSerializeMethod);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to compare _idGenerator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so. Looks like I missed it.

</ItemGroup>

<ItemGroup>
<None Include="..\..\THIRD-PARTY-NOTICES" Pack="true" PackagePath="\" />
<Folder Include="Shared\" />
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question as in Bson project.


var result = x.Equals(y);

result.Should().Be(notEqualFieldName == null ? true : false);
Copy link
Contributor

Choose a reason for hiding this comment

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

notEqualFieldName can't be 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.

I will remove the null check. It's left over from some intermediate experiments.


private BsonClassMap Clone(BsonClassMap classMap)
{
var clone = (BsonClassMap)FormatterServices.GetUninitializedObject(classMap.GetType());
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have to use the Reflector here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we do because there is no easy way to change just ONE field at a time to test Equals, but we can do it easily using reflection.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have avoided using reflection wherever possible.

[Fact]
public void Equals_with_equal_fields_should_return_true()
{
var x = (StandardDiscriminatorConvention)new ConcreteStandardDiscriminatorConvention("_t");
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: is this cast needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depends how you define "needed".

I wanted the compile time type of x to be the abstract base class, not the concrete type.

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