DynamicData icon indicating copy to clipboard operation
DynamicData copied to clipboard

Virtualise and Page cause exception on non-unique list

Open navozenko opened this issue 4 years ago • 2 comments

Virtualise and Page methods cause ArgumentOutOfRangeException if the list contains equal elements. Is it by design or a bug?

var source = new SourceList<string>();
source.AddRange(Enumerable.Repeat("item", 10));
source.Connect()
    .Virtualise(new BehaviorSubject<IVirtualRequest>(new VirtualRequest(0, 3)))
    .Subscribe();

or

var source = new SourceList<string>();
source.AddRange(Enumerable.Repeat("item", 10));
source.Connect()
    .Page(new BehaviorSubject<IPageRequest>(new PageRequest(0, 3)))
    .Subscribe();

Tested on version 7.4.9

navozenko avatar Dec 19 '21 08:12 navozenko

The exception seems to occur because Virtualise and Page use LINQ Except method to detect added and removed items.

var adds = current.Except(previous);
var removes = previous.Except(current);

This approach works fine when all items in the list are unique, but fails when there are equal items.

navozenko avatar Dec 19 '21 09:12 navozenko

Out of interest, is there an obvious and easy alternative to using linq?

RolandPheasant avatar Apr 29 '22 15:04 RolandPheasant

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Dec 10 '22 01:12 github-actions[bot]