NP.ObjectComparison
0.9.9
See the version list below for details.
dotnet add package NP.ObjectComparison --version 0.9.9
NuGet\Install-Package NP.ObjectComparison -Version 0.9.9
<PackageReference Include="NP.ObjectComparison" Version="0.9.9" />
paket add NP.ObjectComparison --version 0.9.9
#r "nuget: NP.ObjectComparison, 0.9.9"
// Install NP.ObjectComparison as a Cake Addin #addin nuget:?package=NP.ObjectComparison&version=0.9.9 // Install NP.ObjectComparison as a Cake Tool #tool nuget:?package=NP.ObjectComparison&version=0.9.9
NP.ObjectComparison
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:
- 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; }
}
- 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 | 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.
Rename the `Skip` related functionality to `Ignore` in order to follow the general naming conventions.
On `ComparisonTracker`
- The history item that is reverted uses a copy of the item.
- Simplify constructor.