-
Notifications
You must be signed in to change notification settings - Fork 7
Equ all the way down #25
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
Open
ibebbs
wants to merge
8
commits into
thedmi:master
Choose a base branch
from
ibebbs:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b774b1b
ElementwiseSequenceEqualityComparer now uses MemberwiseEqualityConver…
ibebbs 8195821
All tests passing.
ibebbs 1b8d576
Removed all conditional compilation directives
ibebbs 3e544fb
Completed clean up
ibebbs aa8034e
Restored previous behaviour of `MemberwiseEqualityComparer<T>.ByField…
ibebbs 6a249fa
Restored commented out tests
ibebbs 419fc67
`MemberwiseEqualityComparer<T>.ByFieldRecursive` & `MemberwiseEqualit…
ibebbs 9585179
Now handles classes which reference themselves
ibebbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,3 +20,4 @@ _ReSharper*/ | |
| Sources/packages | ||
| *.nupkg | ||
| /Sources/.vs/Equ/v15/Server/sqlite3/* | ||
| **/.vs | ||
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "CurrentProjectSetting": null | ||
| } |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| using System.Collections.Generic; | ||
| using Xunit; | ||
|
|
||
| namespace Equ.Test | ||
| { | ||
| public class NestedClassTest | ||
| { | ||
| public class Contained | ||
| { | ||
| public string BasicProperty { get; set; } | ||
| public Contained Nested { get; set; } | ||
| } | ||
|
|
||
| public class Container | ||
| { | ||
| public Contained Nested { get; set; } | ||
| } | ||
|
|
||
| public static IEnumerable<object[]> ShouldDetermineCorrectEqualityTests => new List<object[]> | ||
| { | ||
| new object[] { new Container(), new Container(), MemberwiseEqualityComparer<Container>.ByProperties, true }, | ||
| new object[] { | ||
| new Container { Nested = new Contained() }, | ||
| new Container { }, | ||
| MemberwiseEqualityComparer<Container>.ByProperties, | ||
| false | ||
| }, | ||
| new object[] { | ||
| new Container { Nested = new Contained() }, | ||
| new Container { Nested = new Contained() }, | ||
| MemberwiseEqualityComparer<Container>.ByProperties, | ||
| false | ||
| }, | ||
| new object[] { | ||
| new Container { Nested = new Contained() }, | ||
| new Container { Nested = new Contained() }, | ||
| MemberwiseEqualityComparer<Container>.ByPropertiesRecursive, | ||
| true | ||
| }, | ||
| new object[] { | ||
| new Container { Nested = new Contained { Nested = new Contained() } }, | ||
| new Container { Nested = new Contained() }, | ||
| MemberwiseEqualityComparer<Container>.ByPropertiesRecursive, | ||
| false | ||
| }, | ||
| new object[] { | ||
| new Container { Nested = new Contained { Nested = new Contained() } }, | ||
| new Container { Nested = new Contained { Nested = new Contained() } }, | ||
| MemberwiseEqualityComparer<Container>.ByPropertiesRecursive, | ||
| true | ||
| } | ||
| }; | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(ShouldDetermineCorrectEqualityTests))] | ||
| public void ShouldDetermineCorrectEquality(Container x, Container y, MemberwiseEqualityComparer<Container> equalityComparer, bool expected) | ||
| { | ||
| Assert.Equal(expected, equalityComparer.Equals(x, y)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Text; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace Equ.Test | ||
| { | ||
| public class NestedCollectionsTest | ||
| { | ||
| public class Level2 | ||
| { | ||
| public string BasicProperty { get; set; } | ||
| } | ||
|
|
||
| public class Level1 | ||
| { | ||
| public ICollection<Level2> Items { get; set; } | ||
| } | ||
|
|
||
| public class Container | ||
| { | ||
| public ICollection<Level1> Items { get; set; } | ||
| } | ||
|
|
||
| public static IEnumerable<object[]> ShouldDetermineCorrectEqualityTests => new List<object[]> | ||
| { | ||
| new object[] { new Container(), new Container(), MemberwiseEqualityComparer<Container>.ByProperties, true }, | ||
| new object[] { | ||
| new Container { Items = new List<Level1>() }, | ||
| new Container { }, | ||
| MemberwiseEqualityComparer<Container>.ByProperties, | ||
| false | ||
| }, | ||
| new object[] { | ||
| new Container { Items = new List<Level1>() }, | ||
| new Container { Items = new List<Level1>() }, | ||
| MemberwiseEqualityComparer<Container>.ByProperties, | ||
| true | ||
| }, | ||
| new object[] { | ||
| new Container { Items = new List<Level1>() }, | ||
| new Container { Items = Array.Empty<Level1>() }, | ||
| MemberwiseEqualityComparer<Container>.ByProperties, | ||
| true | ||
| }, | ||
| new object[] { | ||
| new Container { Items = new [] { new Level1() } }, | ||
| new Container { Items = Array.Empty<Level1>() }, | ||
| MemberwiseEqualityComparer<Container>.ByProperties, | ||
| false | ||
| }, | ||
| new object[] { | ||
| new Container { Items = new [] { new Level1() } }, | ||
| new Container { Items = new [] { new Level1() } }, | ||
| MemberwiseEqualityComparer<Container>.ByProperties, | ||
| false | ||
| }, | ||
| new object[] { | ||
| new Container { Items = new [] { new Level1() } }, | ||
| new Container { Items = new [] { new Level1() } }, | ||
| MemberwiseEqualityComparer<Container>.ByPropertiesRecursive, | ||
| true | ||
| }, | ||
| new object[] { | ||
| new Container { Items = new [] { new Level1 { Items = new[] { new Level2() } } } }, | ||
| new Container { Items = new [] { new Level1 { Items = new[] { new Level2() } } } }, | ||
| MemberwiseEqualityComparer<Container>.ByProperties, | ||
| false | ||
| }, | ||
| new object[] { | ||
| new Container { Items = new [] { new Level1 { Items = new[] { new Level2() } } } }, | ||
| new Container { Items = new [] { new Level1 { Items = new[] { new Level2() } } } }, | ||
| MemberwiseEqualityComparer<Container>.ByPropertiesRecursive, | ||
| true | ||
| }, | ||
| }; | ||
|
|
||
| [Theory] | ||
| [MemberData(nameof(ShouldDetermineCorrectEqualityTests))] | ||
| public void ShouldDetermineCorrectEquality(Container x, Container y, MemberwiseEqualityComparer<Container> equalityComparer, bool expected) | ||
| { | ||
| Assert.Equal(expected, equalityComparer.Equals(x, y)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
|
|
||
| namespace Equ | ||
| { | ||
| public class EqualityFunctionContext | ||
| { | ||
| private readonly Dictionary<Type, MemberwiseEqualityComparer> _equalityComparers; | ||
|
|
||
| public EqualityFunctionContext(MemberwiseEqualityMode mode) | ||
| { | ||
| _equalityComparers = new Dictionary<Type, MemberwiseEqualityComparer>(); | ||
|
|
||
| Mode = mode; | ||
|
|
||
| MemberwiseEqualityComparerProperty = mode switch | ||
| { | ||
| MemberwiseEqualityMode.ByFields => nameof(MemberwiseEqualityComparer<object>.ByFields), | ||
| MemberwiseEqualityMode.ByFieldsRecursive => nameof(MemberwiseEqualityComparer<object>.ByFieldsRecursive), | ||
| MemberwiseEqualityMode.ByProperties => nameof(MemberwiseEqualityComparer<object>.ByProperties), | ||
| MemberwiseEqualityMode.ByPropertiesRecursive => nameof(MemberwiseEqualityComparer<object>.ByPropertiesRecursive), | ||
| _ => string.Empty | ||
| }; | ||
|
|
||
| ElementwiseSequenceEqualityComparerProperty = mode switch | ||
| { | ||
| MemberwiseEqualityMode.ByFieldsRecursive => nameof(ElementwiseSequenceEqualityComparer<IEnumerable<object>>.ByFieldsRecursive), | ||
| MemberwiseEqualityMode.ByPropertiesRecursive => nameof(ElementwiseSequenceEqualityComparer<IEnumerable<object>>.ByPropertiesRecursive), | ||
| _ => nameof(ElementwiseSequenceEqualityComparer<IEnumerable<object>>.Default) | ||
| }; | ||
| } | ||
|
|
||
| public bool TryGetEqualityComparer(Type type, out MemberwiseEqualityComparer equalityComparer) | ||
| { | ||
| return _equalityComparers.TryGetValue(type, out equalityComparer); | ||
| } | ||
|
|
||
| public void Add<T>(MemberwiseEqualityComparer<T> equalityComparer) | ||
| { | ||
| _equalityComparers.Add(typeof(T), equalityComparer); | ||
| } | ||
|
|
||
| public MemberwiseEqualityMode Mode { get; } | ||
| public bool IsRecursive => Mode == MemberwiseEqualityMode.ByFieldsRecursive || Mode == MemberwiseEqualityMode.ByPropertiesRecursive; | ||
| public string MemberwiseEqualityComparerProperty { get; } | ||
| public string ElementwiseSequenceEqualityComparerProperty { get; } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I don't think I've seen this syntax before. I haven't paid much attention to the new features for a few years though. What is it doing?
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's C# 8.0's pattern matching: https://docs.microsoft.com/en-us/archive/msdn-magazine/2019/may/csharp-8-0-pattern-matching-in-csharp-8-0