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

ignore collection count #256

Merged
merged 7 commits into from
Mar 18, 2022
Merged

ignore collection count #256

merged 7 commits into from
Mar 18, 2022

Conversation

sebasijan
Copy link

No description provided.

@GregFinzer
Copy link
Owner

Thanks for the pull request submission. This implementation is going to confuse people later. If the counts are different and one list is longer than the other then the longer list items will not be compared. Please make a IReadOnlyCollectionComparer and ignore the count when CompareReadOnly == false

@GregFinzer
Copy link
Owner

I am thinking that maybe the IReadOnlyCollection would not be compared at all if CompareReadOnly == false

seb k added 4 commits March 11, 2022 06:42
…n/Compare-Net-Objects into ignore-collection-count

# Conflicts:
#	Compare-NET-Objects-Tests/IgnoreTests.cs
@sebasijan
Copy link
Author

sebasijan commented Mar 11, 2022

I just realised that your last comment suggests ignoring the entire collection, but I am hoping to have the functionality of just ignoring the Count property specifically, do you have any suggestions for doing that?

@GregFinzer
Copy link
Owner

Now this is just a defect that is specific to a read only collection.

What I would do is simply this:

  1. Set IgnoreCollectionOrder = true
  2. Just not use the count property in your output:

var differencesWithoutCount = Differences.Where(o => o.ChildPropertyName != "Count" && !o.Object1TypeName.Contains("ReadOnlyCollection"));
string result = differencesWithoutCount.Aggregate(string.Empty, (current, difference) => current + (difference + Environment.NewLine));

@sebasijan
Copy link
Author

Ye that is my current approach, but I'm not a huge fan because I then need to specify the same for every type of collection I might be using in my classes

I just thought that it made sense to exclude Count when setting CompareReadOnly = false, since Count is in fact a readonly property

I can always just add the filter for any collection type I happen to be using

@sebasijan
Copy link
Author

sebasijan commented Mar 11, 2022

Updated the PR to simply ignore ReadOnlyCollections when CompareReadOnly = true

@GregFinzer GregFinzer merged commit 80bd7eb into GregFinzer:master Mar 18, 2022
@GregFinzer
Copy link
Owner

@sebasijan sebasijan deleted the ignore-collection-count branch April 29, 2022 10:48
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.

2 participants