Skip to content

Get the [Insert, Delete, Move, Replace] operations to apply on collection A to obtain collection B.

License

Notifications You must be signed in to change notification settings

jeanplevesque/CollectionTracking

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

CollectionTracking

License Version Downloads

Goal

This package was developed to interpret a series of immutable lists (from a business layer) as one mutable lists (in a presentation layer). In other words, convert IObservable<IEnumerable<T>> to ObservableCollection<T>.

Usage

1. Get the differences

Use CollectionTracker.GetOperations to compare 2 enumerables.

using CollectionTracking;

// (...)

var source = new[] { "B", "C", "A" };
var target = new[] { "A", "B", "C", "D" };

var operations = CollectionTracker.GetOperations(source, target);

foreach (var operation in operations)
{
	Console.WriteLine(operation);
}

This code prints the following.

Move 'A' from [2] to [0]
Insert 'D' at [3]

2. Use the differences to modify an IList

Use CollectionTracker.ApplyOperations to apply a series of CollectionOperations on an IList.

var list = source.ToList();
list.ApplyOperations(operations);

This code initializes the list variable with the content being [BCA]. The ApplyOperations modifies that list so that it becomes [ABCD]. This is very useful when manipulating an ObservableCollection bound to a UI component (such as ItemsControl.ItemsSource).

CollectionTracking.DynamicData

Goal

Expose conversion methods to relevant types from the DynamicData library.

Usage

using CollectionTracking;
using DynamicData;

// (...)

var source = new[] { "B", "C", "A" };
var target = new[] { "A", "B", "C", "D" };

var operations = CollectionTracker.GetOperations(source, target);

// Convert all changes.
IChangeSet<string> changeSet = operations.ToChangeSet();

// Convert a single change.
Change<string> change = operations[0].ToChange();

About

Get the [Insert, Delete, Move, Replace] operations to apply on collection A to obtain collection B.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages