NP.ObjectComparison 0.9.8.2

There is a newer version of this package available.
See the version list below for details.

Requires NuGet 2.12 or higher.

dotnet add package NP.ObjectComparison --version 0.9.8.2                
NuGet\Install-Package NP.ObjectComparison -Version 0.9.8.2                
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.8.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NP.ObjectComparison --version 0.9.8.2                
#r "nuget: NP.ObjectComparison, 0.9.8.2"                
#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.8.2

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

NP.ObjectComparison

CI Build CD Build 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 [SkipAnalyze] on a property or a class.

For a property:

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

For a class:

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

// Skipping properties
var propertyInfo = typeToSkip.GetProperty(nameof(ToBeAnalyzed.Value));
analyzerSettings.SkipAnalyzeSettings.Skip(propertyInfo);

// OR
analyzerSettings
	.SkipAnalyzeSettings
	.Skip<ToBeAnalyzed, string>(model => model.Value)


// Skipping classes
analyzerSettings.SkipAnalyzeSettings.Skip(typeToSkip);

// OR
analyzerSettings.SkipAnalyzeSettings.Skip<ToBeAnalyzed>();

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

Roadmap

  • Add PatchInfo as return value to include more detailed patch information.
  • Consider creating diff functionality as well ? (That can commit after ? )
  • Finish Depth functionality on Patch
  • Add Depth functionality on Diff code
  • Maybe make a Diff functionality that can apply the patch later by calling a method ?
  • Figure out how to publish alpha packages outside of nuget.org
  • Make a Decorator that will provide the full comparison functionality
  • Add AutoAnalyze in HasChanges
  • Make Factory extensions
  • Make the README better
  • Make Ignore Attributes etc
    • Make analyzer settings take a Default factory.
  • Give the option to also revert a patch (is it possible?)
    • If these 2 work we can go one step further and keep a history of DiffAnalysisResults that can be applied or get reverted ?
  • Make a Memento object that will keep the history of the changes ?
  • Rename Skip to Ignore to follow general naming conventions.
  • Make the Comparison Tracker to have an index that will return the change tracking of that field like (ComparisonTracker["path.to.property"])
  • Make the comparison tracker to make use of the WeakReference class.
  • Make examples and samples
  • Unit Tests
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 565 4/8/2022
0.9.9 454 3/9/2022
0.9.8.3 411 3/8/2022
0.9.8.2 423 3/8/2022
0.9.8.1 448 2/24/2022

Update nuget package info.