IVSoftware.Portable.Reconciler
1.0.2
Prefix Reserved
See the version list below for details.
dotnet add package IVSoftware.Portable.Reconciler --version 1.0.2
NuGet\Install-Package IVSoftware.Portable.Reconciler -Version 1.0.2
<PackageReference Include="IVSoftware.Portable.Reconciler" Version="1.0.2" />
paket add IVSoftware.Portable.Reconciler --version 1.0.2
#r "nuget: IVSoftware.Portable.Reconciler, 1.0.2"
// Install IVSoftware.Portable.Reconciler as a Cake Addin #addin nuget:?package=IVSoftware.Portable.Reconciler&version=1.0.2 // Install IVSoftware.Portable.Reconciler as a Cake Tool #tool nuget:?package=IVSoftware.Portable.Reconciler&version=1.0.2
IVSoftware.Portable.Reconciler
Reconciler
class encapsulates a static
method to efficiently sort the two lists into five categories, using the sort and compare criteria supplied to the method.
Categories
- Items that are only contained in the A list.
- Items that are only contained in the B list.
- Items that are contained in both lists, where A has the newer time stamp.
- Items that are contained in both lists, where B has the newer time stamp.
- Items whose sort criteria and time stamps are identical.
Method
/// <summary>
/// Static method to categorize two collections of items.
/// </summary>
/// <param name="srceA">An enumerable collection of T informally known as the A List.</param>
/// <param name="srceB">An enumerable collection of T informally known as the B List.</param>
/// <param name="uidSorter">A CompareUIDResult method that compares two T objects for sorting.</param>
/// <param name="versionComparer">A CompareVersionResult method that compares two T objects for <, >, == </param>
/// <param name="resultSorter">Optional Comparer T to return values in order.</param>
/// <returns>Reconciled T</returns>
/// <exception cref="NotImplementedException"></exception>
public static Reconciled<T> Reconcile<T>(
IEnumerable<T> srceA,
IEnumerable<T> srceB,
Func<T, T, CompareUIDResult> uidSorter,
Func<T, T, CompareVersionResult> versionComparer,
Func<T, T, int> resultSorter = null
);
Example class
class DatabaseRecord
{
public object Guid { get; }
public DateTime TimeStamp { get; }
// Other properties...
}
CompareUIDResult Example
Named delegate
The uidSorter sorts in ascending order. This argument can be passed by making a named method and passing 'just' the name:
CompareUIDResult CompareUID<DatabaseRecord>(a,b) => (CompareUIDResult)a.Guid.CompareTo(b.Guid);
In this case the argument would be uidSorter: CompareUID
,
Anonymous delegate
It's usually easier to use an anonymous delegate and pass the method inline:
In this case the argument would be uidSorter: (a,b)=> (CompareUIDResult)a.Guid.CompareTo(b.Guid)
VersionComparer example
Named delegate
The versionComparer sorts in descending order. This argument can be passed by making a named method and passing 'just' the name:
CompareVersionResult CompareVersion<DatabaseRecord>(a,b) => (CompareVersionResult)a.TimeStamp.CompareTo(b.TimeStamp);
In this case the argument would be versionComparer: CompareUID
,
Anonymous delegate
It's usually easier to use an anonymous delegate and pass the method inline:
In this case the argument would be versionComparer: (a,b)=> (CompareVersionResult)a.TimeStamp.CompareTo(b.TimeStamp)
Reconciled return class
Properties
/// <summary>
/// Items that are only contained in the A list.
/// </summary>
public T[] OnlyInA { get; }
/// <summary>
/// Items contained in both lists, where A has the newer time stamp.
/// </summary>
public T[] NewerInA { get; }
/// <summary>
/// Items that are only contained in the B list.
/// </summary>
public T[] OnlyInB { get; }
/// <summary>
/// Items contained in both lists, where B has the newer time stamp.
/// </summary>
public T[] NewerInB { get; }
/// <summary>
/// Items contained in both lists, whose sort criteria and time stamps are identical.
/// </summary>
public Tuple<T, T>[] Equal { get; }
/// <summary>
/// Detects whether the two lists are 'not' in sync.
/// </summary>
public bool HasChanges { get;}
/// <summary>
/// Using the item that 'is' newer as a key,
/// returns the item that 'is not' newer
/// </summary>
public Dictionary<T, T> Not { get; }
Method
/// <summary>
/// Verbose listing of the items in their categories.
/// </summary>
public override string ToString();
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.