UpdateCollection 1.0.1

dotnet add package UpdateCollection --version 1.0.1
NuGet\Install-Package UpdateCollection -Version 1.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="UpdateCollection" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add UpdateCollection --version 1.0.1
#r "nuget: UpdateCollection, 1.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install UpdateCollection as a Cake Addin
#addin nuget:?package=UpdateCollection&version=1.0.1

// Install UpdateCollection as a Cake Tool
#tool nuget:?package=UpdateCollection&version=1.0.1

.NET - UpdateCollection

GitHub Travis (.org) branch Nuget

Update a collection with another collection in .NET

It can be a pain to update a collection using another collection. This library is designed to make this process easier, with a simple fluent API.

Example usage

  var destination = new List<Item> 
  { 
      new Item { Id = 1, Name = "A" },
      new Item { Id = 2, Name = "B" }
  };
  
  var source = new List<Item>
  {
      new Item { Id = 1, Name = "B" },
      new Item { Id = 3, Name = "C" }
  };

  destination = destination
      .UsingSource(source)
      .CompareWith((d, s) => d.Id == s.Id)
      .CreateWith(s => new Item { Id = s.Id, Name = s.Name, Date = DateTime.Now })
      .UpdateWith((d, s) => { d.Name = s.Name + " updated"; })
      .WithDelete()
      .Execute();

The above code would:

  • Update the exiting item where Id = 1 to have Name = "B updated"
  • Create a new item where Id = 3 and Name = "C updated"
  • Delete item where Id = 2 which doesn't exist in the source collection

Methods

.UsingSource(IEnumerable<T> source)

  • The entry point for UpdateCollection.
  • Call this extension method on an existing IEnumerable<TDestination> instance.
  • (param: source) A source IEnumerable<TSource> instance which is used to create/update/delete items in the destination. It does not have to be of the same type as the destination.

.CompareWith((TDestination, TSource) => bool)

  • To be chained to .UsingSource()
  • (param: func) A delegate that returns a boolean which is called for each item in the source collection as a comparator to use which looks for a match against an item in the destination collection.

.CreateWith(TSource => TDestination)

  • Optional method which can be chained to .CompareWith()
  • (param: func) A delegate that returns an instance of TDestination which is called for each item in the source collection that needs to be created in the destination. It provides the current source item which can be used to construct a destination item.

.UpdateWith((TDestination, TSource) => void)

  • Optional method which can be chained to .CompareWith() or .CreateWith()
  • (param: func) A delegate that returns an instance of TDestination which is called for each item in the source collection that needs to be created in the destination. It provides the current source item which can be used to construct a destination item.
  • You must create the TDestination item yourself as it is not created automatically.

.WithDelete()

  • Optional method which can be chained to .CreateWith() or .UpdateWith()
  • Remove any items from the destination which do not exist in the source, based on the delegate in .CompareWith()

.Execute()

  • Required. Must be called last and can be chained to .CreateWith(), .UpdateWith() or .WithDelete()
  • Returns the new and updated version of the destination collection
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .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.

Version Downloads Last updated
1.0.1 496 1/15/2020
1.0.0 625 5/25/2019