NP.ObjectComparison
0.9.8.2
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
<PackageReference Include="NP.ObjectComparison" Version="0.9.8.2" />
paket add NP.ObjectComparison --version 0.9.8.2
#r "nuget: NP.ObjectComparison, 0.9.8.2"
// 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
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
[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; }
}
- 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 PatchAdd Depth functionality on Diff codeMaybe make a Diff functionality that can apply the patch later by calling a method ?Figure out how to publish alpha packages outside of nuget.orgMake a Decorator that will provide the full comparison functionalityAdd AutoAnalyze in HasChangesMake Factory extensionsMake the README betterMake Ignore Attributes etcMake 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 | 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.
Update nuget package info.