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

ErrorOr<TValue> and Error now behave like Value Objects #97

Merged
merged 2 commits into from
May 9, 2024

Conversation

feO2x
Copy link
Contributor

@feO2x feO2x commented Apr 27, 2024

This PR fixes #85 by explicitly implementing Equals and GetHashCode for the ErrorOr<TValue> and Error record structs. In them, we perform a deep comparison for the errors list and metadata dictionary, respectively. I also include unit tests that cover these implementations.

I introduced the runtime dependency Microsoft.Bcl.HashCode so that I can use the HashCode struct both in .NET Standard 2.0 and .NET 6. If we do not want this dependency for .NET Standard 2.0, we should copy over the source code of HashCode - please let me know how you want to deal with this.

I also introduced Nullable, but this is not a runtime dependency. It is simply there so that I can use the MemberNotNullWhenAttribute in .NET Standard 2.0, too. This helps Roslyn with tracking whether _value or _errors is null when IsErrors was called beforehand in ErrorOr<TValue>.

This commit implements Equals and GetHashCode for the
ErrorOr<TValue> struct so that a deep comparison with the
errors list is performed (instead of the default reference
equality comparison). I introduced Microsoft.Bcl.HashCode for
.NET Standard 2.0 because I did not want to reinvent the wheel
for the HashCode class. If we do not want this dependency
then we should copy over the source code for .NET Standard 2.0.

Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
This commit implements Equals and GetHashCode in the same way
that the previous commit implemented it for ErrorOr<TValue>.

Signed-off-by: Kenny Pflug <kenny.pflug@live.de>
@amantinband amantinband merged commit 6908e45 into amantinband:main May 9, 2024
1 check passed
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.

[Bug] Error equality not working as intended
2 participants