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

Turn Matches and IsExactly into EqualityComparer<Base> #2928

Open
ewoutkramer opened this issue Oct 18, 2024 · 1 comment
Open

Turn Matches and IsExactly into EqualityComparer<Base> #2928

ewoutkramer opened this issue Oct 18, 2024 · 1 comment

Comments

@ewoutkramer
Copy link
Member

We can rewrite Matches and IsExactly in terms of GetElementPairs(), or even IReadOnlyDictionary. This could be done as in-place replacements for the current methods (who then don't need to be virtual anymore), but we could also turn them into a ExactEqualityComparer<T> and PatternEqualityComparer<T> to align with the normal .NET strategy of implementing System.Collections.Generic.EqualityComparer<Base> for these kind of purposes.

Again, as a guide to the user, we can leave the old methods in, throw not implemented and add an Obsolete with a message to indicate you should use the comparers.

@ewoutkramer
Copy link
Member Author

Since using GetElementPairs() is slower than the current generated approach, it's also possible to use a SourceGenerator to generate these comparers, so the users does not have to hand-write them. Maybe a nice follow up project ;-)

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

No branches or pull requests

1 participant