NP.ObjectComparison 0.9.9.1

dotnet add package NP.ObjectComparison --version 0.9.9.1
NuGet\Install-Package NP.ObjectComparison -Version 0.9.9.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="NP.ObjectComparison" Version="0.9.9.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NP.ObjectComparison --version 0.9.9.1
#r "nuget: NP.ObjectComparison, 0.9.9.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 NP.ObjectComparison as a Cake Addin
#addin nuget:?package=NP.ObjectComparison&version=0.9.9.1

// Install NP.ObjectComparison as a Cake Tool
#tool nuget:?package=NP.ObjectComparison&version=0.9.9.1

NP.ObjectComparison

CI Build CD Build Release Nuget

The NP.ObjectComparison library provides object difference and patching functionality through .NET API.

Installation

To install the package to a project:

dotnet add {PROJECT} package NP.ObjectComparison

The package source for dev streams can be added through:

dotnet nuget add source --name github "https://nuget.pkg.github.com/NickPolyder/index.json"

Usage

The simplest way to start using the library is to initialize an ComparisonTracker object.

var sampleInstance = new SampleClass();
var comparisonTracker = new ComparisonTracker<SampleClass>(sampleInstance);

In order to properly use the ComparisonTracker<T> the T needs to be a class that inherits from System.ICloneable or make use of the CloneFactory delegate through the constructor.

var sampleInstance = new SampleClass();
var comparisonTracker = new ComparisonTracker<SampleClass>(sampleInstance, instance => new SampleClass
   {
	 FirstName = (string)instance.FistName.Clone(),
	 LastName = (string)instance.LastName.Clone(),
	 Age = instance.Age, 
		 RegistrationDate = instance.RegistrationDate,		
   });

When the default Comparison capabilities do not cover the use case there is the possibility to create your own IObjectAnalyzer<in T>. You can find examples on how to create Object Analyzers in the Samples.

var sampleInstance = new SampleClass();
var sampleObjectAnalyzer = new SampleObjectAnalyzer();
var comparisonTracker = new ComparisonTracker<SampleClass>(sampleInstance, sampleObjectAnalyzer);

Ignoring properties

To ignore a property or a class there are two ways available:

  1. By using the attribute [Ignore] from the namespace: NP.ObjectComparison.Attributes on a property or a class.

For a property:

using NP.ObjectComparison.Attributes;

public class ToBeAnalyzed
{
	[Ignore]
	public string Value { get; set; }
}

For a class:

using NP.ObjectComparison.Attributes;

[Ignore]
public class ToBeAnalyzed
{	
	public string Value { get; set; }
}
  1. By providing an initialized instance of AnalyzerSettings
var analyzerSettings = new AnalyzerSettings();
var typeToIgnore = typeof(ToBeAnalyzed);

// Ignoring properties
var propertyInfo = typeToIgnore.GetProperty(nameof(ToBeAnalyzed.Value));
analyzerSettings.IgnoreSettings.Ignore(propertyInfo);

// OR
analyzerSettings
	.IgnoreSettings
	.Ignore<ToBeAnalyzed, string>(model => model.Value)


// Ignoring classes
analyzerSettings.IgnoreSettings.Ignore(typeToIgnore);

// OR
analyzerSettings.IgnoreSettings.Ignore<ToBeAnalyzed>();

// Set the new instance
AnalyzerSettings.DefaultSettings = () => analyzerSettings;

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
0.9.9.1 523 4/8/2022
0.9.9 428 3/9/2022
0.9.8.3 389 3/8/2022
0.9.8.2 401 3/8/2022
0.9.8.1 427 2/24/2022

Performance fixes.