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

Exclude primitive types when comparing by members #1394

Merged

Conversation

jnyrup
Copy link
Member

@jnyrup jnyrup commented Sep 26, 2020

As primitive types do not have members, it does not make sense to try to compare them by members.
On all but one of the target frameworks two different primitives are currently incorrectly evaluated as being equivalent (#1374).
On net472 it will even hit "The maximum recursion depth was reached".

This PR excludes primitive types from being compared by members.

Thought:
Should we add a guard check in ComparingByMembers if someone writes
ComparingByMembers<int>() and wonders why ints are still not compared by members?

For those interested in the complete set of primitive types, here are the facts from in .netcoreapp3.0

AllTypes
  .From(typeof(int).Assembly)
  .Where(e => e.IsPrimitive)
  .Select(e => e.Name)
  .ToList();
"Boolean"
"Byte"
"Char"
"Double"
"Int16"
"Int32"
"Int64"
"IntPtr"
"SByte"
"Single"
"UInt16"
"UInt32"
"UInt64"
"UIntPtr"

@dennisdoomen
Copy link
Member

Should we add a guard check in ComparingByMembers if someone writes
ComparingByMembers() and wonders why ints are still not compared by members?

Yes, I think it should throw an InvalidOperationException

Copy link
Member

@dennisdoomen dennisdoomen left a comment

Choose a reason for hiding this comment

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

Don't we need some update to the docs and release notes?

@jnyrup
Copy link
Member Author

jnyrup commented Sep 26, 2020

🤦 Completely forgot about docs and release notes .

@dennisdoomen
Copy link
Member

@jnyrup jnyrup force-pushed the structuralEqualityOnPrimitives branch from c8b10e4 to 3e5a001 Compare September 26, 2020 15:06
@jnyrup
Copy link
Member Author

jnyrup commented Sep 26, 2020

Added notes to the object graphs section.

@jnyrup jnyrup force-pushed the structuralEqualityOnPrimitives branch from 3e5a001 to e80bb9a Compare September 26, 2020 15:17
@jnyrup jnyrup merged commit 410ea1e into fluentassertions:develop Sep 26, 2020
@jnyrup jnyrup deleted the structuralEqualityOnPrimitives branch September 26, 2020 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants