Class Merge
Provides utility methods for merging ICollection<T>s.
Namespace: NanoByte.Common.Dispatch
Assembly: NanoByte.Common.dll
Syntax
public static class Merge : Object
Methods
ThreeWay<T>(IEnumerable<T>, IEnumerable<T>, IEnumerable<T>, Action<T>, Action<T>)
Performs a 3-way merge on a set of collections. Changes between reference
and theirs
as they apply to mine
are emitted using callback delegates.
Declaration
public static void ThreeWay<T>(IEnumerable<T> reference, IEnumerable<T> theirs, IEnumerable<T> mine, Action<T> added, Action<T> removed)
where T : class, IMergeable<T>
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | reference | A common baseline from which both |
IEnumerable<T> | theirs | The foreign list with changes that shall be merged in. |
IEnumerable<T> | mine | The local list that shall be updated with foreign changes. |
Action<T> | added | Called for every element that should be added to |
Action<T> | removed | Called for every element that should be removed from |
Type Parameters
Name | Description |
---|---|
T |
Remarks
Modified elements are handled by calling removed
for the old state and added
for the new state.
ThreeWay<T, TAdded, TRemoved>(IEnumerable<T>, IEnumerable<T>, IEnumerable<T>, ICollection<TAdded>, ICollection<TRemoved>)
Performs a 3-way merge on a set of collections. Changes between reference
and theirs
as they apply to mine
are recorded using differential lists.
Declaration
public static void ThreeWay<T, TAdded, TRemoved>(IEnumerable<T> reference, IEnumerable<T> theirs, IEnumerable<T> mine, ICollection<TAdded> added, ICollection<TRemoved> removed)
where T : class, IMergeable<T>, TAdded, TRemoved
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | reference | A common baseline from which both |
IEnumerable<T> | theirs | The foreign list with changes that shall be merged in. |
IEnumerable<T> | mine | The local list that shall be updated with foreign changes. |
ICollection<TAdded> | added | All elements that should be added to |
ICollection<TRemoved> | removed | All elements that should be removed from |
Type Parameters
Name | Description |
---|---|
T | |
TAdded | |
TRemoved |
Remarks
Modified elements are handled by adding to removed
for the old state and to added
for the new state.
TwoWay<T>(IEnumerable<T>, IEnumerable<T>, Action<T>, Action<T>)
Performs a 2-way merge on two collections. Changes required to theirs
to reflect mine
are emitted using callback delegates.
Declaration
public static void TwoWay<T>(IEnumerable<T> theirs, IEnumerable<T> mine, Action<T> added, Action<T> removed)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | theirs | The foreign list with changes that shall be merged in. |
IEnumerable<T> | mine | The local list that shall be updated with foreign changes. |
Action<T> | added | Called for every element that should be added to |
Action<T> | removed | Called for every element that should be removed from |
Type Parameters
Name | Description |
---|---|
T |
Remarks
theirs
and mine
should use an internal hashmap for Contains(T) for better performance.
TwoWay<T, TAdded, TRemoved>(IEnumerable<T>, IEnumerable<T>, ICollection<TAdded>, ICollection<TRemoved>)
Performs a 2-way merge on two collections. Changes required to theirs
to reflect mine
are recorded using differential lists.
Declaration
public static void TwoWay<T, TAdded, TRemoved>(IEnumerable<T> theirs, IEnumerable<T> mine, ICollection<TAdded> added, ICollection<TRemoved> removed)
where T : class, TAdded, TRemoved
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | theirs | The foreign list with changes that shall be merged in. |
IEnumerable<T> | mine | The local list that shall be updated with foreign changes. |
ICollection<TAdded> | added | All elements that should be added to |
ICollection<TRemoved> | removed | All elements that should be removed from |
Type Parameters
Name | Description |
---|---|
T | |
TAdded | |
TRemoved |
Remarks
theirs
and mine
should use an internal hashmap for Contains(T) for better performance.