https://github.com/jeanplevesque/collectiontracking
Get the [Insert, Delete, Move, Replace] operations to apply on collection A to obtain collection B.
https://github.com/jeanplevesque/collectiontracking
collection csharp diffing dotnet
Last synced: 7 months ago
JSON representation
Get the [Insert, Delete, Move, Replace] operations to apply on collection A to obtain collection B.
- Host: GitHub
- URL: https://github.com/jeanplevesque/collectiontracking
- Owner: jeanplevesque
- License: apache-2.0
- Created: 2022-05-06T19:01:43.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-07-11T12:22:17.000Z (over 2 years ago)
- Last Synced: 2025-07-05T16:41:42.491Z (7 months ago)
- Topics: collection, csharp, diffing, dotnet
- Language: C#
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CollectionTracking
[](LICENSE)  
## 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>` to `ObservableCollection`.
## Usage
### 1. Get the differences
Use `CollectionTracker.GetOperations` to compare 2 enumerables.
```csharp
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 `CollectionOperation`s on an `IList`.
```csharp
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](https://github.com/reactivemarbles/DynamicData).
## Usage
```csharp
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 changeSet = operations.ToChangeSet();
// Convert a single change.
Change change = operations[0].ToChange();
```