Skip to content

ignore collection count#256

Merged
GregFinzer merged 7 commits intoGregFinzer:masterfrom
sebasijan:ignore-collection-count
Mar 18, 2022
Merged

ignore collection count#256
GregFinzer merged 7 commits intoGregFinzer:masterfrom
sebasijan:ignore-collection-count

Conversation

@sebasijan
Copy link
Copy Markdown

No description provided.

@GregFinzer
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Owner

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