All Projects β†’ replaysMike β†’ AnyDiff

replaysMike / AnyDiff

Licence: GPL-3.0 license
A CSharp (C#) diff library that allows you to diff two objects and get a list of the differences back.

Programming Languages

C#
18002 projects

Projects that are alternatives of or similar to AnyDiff

Diff Match Patch
Diff Match Patch is a high-performance library in multiple languages that manipulates plain text.
Stars: ✭ 4,910 (+6037.5%)
Mutual labels:  diff, difference
Differencekit
πŸ’» A fast and flexible O(n) difference algorithm framework for Swift collection.
Stars: ✭ 2,986 (+3632.5%)
Mutual labels:  diff, difference
covidtrackerapiwrapper
CovidSharp is a crossplatform C# API wrapper for the Coronavirus tracking API (https://github.com/ExpDev07/coronavirus-tracker-api)
Stars: ✭ 11 (-86.25%)
Mutual labels:  dotnet-standard, csharp-code
speech-recognition-evaluation
Evaluate results from ASR/Speech-to-Text quickly
Stars: ✭ 25 (-68.75%)
Mutual labels:  diff, difference
NetCoreForce
Salesforce REST API toolkit for .NET Standard and .NET Core
Stars: ✭ 77 (-3.75%)
Mutual labels:  dotnet-standard
visual-differ
A Node-based diffing tool to compare an array of URLs and flag differences between them
Stars: ✭ 18 (-77.5%)
Mutual labels:  diff
ETWNetMonv3
ETWNetMonv3 is simple C# code for Monitoring TCP Network Connection via ETW & ETWProcessMon/2 is for Monitoring Process/Thread/Memory/Imageloads/TCPIP via ETW + Detection for Remote-Thread-Injection & Payload Detection by VirtualMemAlloc Events (in-memory) etc.
Stars: ✭ 32 (-60%)
Mutual labels:  csharp-code
MOEAs
This project is implemented by C#, and introduces a algorithm framework of MOEA, and some MOEA algorithms and multi-objective problems are provided.
Stars: ✭ 23 (-71.25%)
Mutual labels:  csharp-code
Nager.VideoStream
Get images from a network camera stream or webcam
Stars: ✭ 27 (-66.25%)
Mutual labels:  dotnet-standard
ReflectionToIL
A demonstration and benchmark of different approaches to load closure fields using reflection and dynamic code generation
Stars: ✭ 30 (-62.5%)
Mutual labels:  dotnet-standard
deltaq
Fast and portable delta encoding for .NET in 100% safe, managed code.
Stars: ✭ 26 (-67.5%)
Mutual labels:  diff
atom-hg
Mercurial support for Atom text editor. Works on Linux, Mac OS X and Windows.
Stars: ✭ 27 (-66.25%)
Mutual labels:  diff
Micro
🏎Fast diffing and type safe SwiftUI style data source for UICollectionView
Stars: ✭ 77 (-3.75%)
Mutual labels:  diff
TreeWalker
PHP JSON diff
Stars: ✭ 58 (-27.5%)
Mutual labels:  diff
FtpServer
An FTP server program for .NET Core, and its customizable .NET Standard core library
Stars: ✭ 28 (-65%)
Mutual labels:  dotnet-standard
NwRfcNet
An easy way of making SAP RFC calls from .NET Core
Stars: ✭ 83 (+3.75%)
Mutual labels:  dotnet-standard
ShippingRates
.NET wrapper to UPS, FedEx, USPS and DHL shipping rates APIs
Stars: ✭ 23 (-71.25%)
Mutual labels:  dotnet-standard
MarkEmbling.PostcodesIO
.NET library for interacting with the excellent Postcodes.io service.
Stars: ✭ 22 (-72.5%)
Mutual labels:  dotnet-standard
diffview.nvim
Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Stars: ✭ 1,472 (+1740%)
Mutual labels:  diff
LiteGui
Immediate Mode GUI From Scratch
Stars: ✭ 15 (-81.25%)
Mutual labels:  csharp-code

AnyDiff

nuget nuget Build status Codacy Badge Codacy Badge

A CSharp (C#) diff library that allows you to diff two objects and get a list of the differences back.

Description

AnyDiff works with complex objects of any type, and is great for performing changeset tracking, auditing, or anything else that might require comparing differences between complex objects. Great when combined with AnyClone, as it lets you take a snapshot of the current state of an object and then compare it in the future for changes to it.

It can even do this for objects that are of different types, though the results may vary depending on how different they are.

Installation

Install AnyDiff from the Package Manager Console:

PM> Install-Package AnyDiff

Usage

Comparing two objects with no differences:

using AnyDiff;

var object1 = new MyComplexObject(1, "A string");
var object2 = new MyComplexObject(1, "A string");
var diff = AnyDiff.Diff(object1, object2);
Assert.AreEqual(diff.Count, 0);

Alternate extension syntax is also available (we will use this in further examples):

using AnyDiff.Extensions;

var object1 = new MyComplexObject(1, "A string");
var object2 = new MyComplexObject(1, "A string");
var diff = object1.Diff(object2);
Assert.AreEqual(diff.Count, 0);

Comparing two objects with a single expected change:

var object1 = new MyComplexObject(1, "A string");
var object2 = new MyComplexObject(1, "A different string");
var diff = object1.Diff(object2);
Assert.AreEqual(diff.Count, 1);

Comparing objects using custom Type Converters for proper delta detection:

public class MyComplexObject
{
  public int Id { get; private set; }

  /// <summary>
  /// Convert a formatted string as a TimeSpan
  /// </summary>
  [TypeConverter(typeof(TimeSpanConverter))]
  public string StartTime { get; set; }

  public TypeConverterObject(int id, string startTime)
  {
    Id = id;
    StartTime = startTime;
  }
}

var object1 = new MyComplexObject(1, "04:00:00");
var object2 = new MyComplexObject(1, "04:05:00");
var diff = object1.Diff(object2);
Assert.AreEqual(diff.Count, 1);
Assert.AreEqual(TimeSpan.FromMinutes(5), diff.First().Delta); // difference of 5 minutes

Ignoring Properties

Anydiff will ignore fields and properties decorated using attributes: [IgnoreDataMember], [NonSerialized], and [JsonIgnore]. In addition, you can specify properties to ignore using expression syntax. See Ignoring Properties and Fields for more details.

Ignoring by properties explicitly by passing a list of properties via expressions:

var object1 = new MyComplexObject(1, "A string", true);
var object2 = new MyComplexObject(2, "A different string", true);
var diff = object1.Diff(object2, x => x.Id, x => x.Name);
Assert.AreEqual(diff.Count, 0);

Diff specified properties only

AnyDiff also supports processing of specific properties if you don't want to diff the entire object. This works using the same syntax as ignoring properties but passing a different ComparisonOptions. In the example below, only the properties Id and Name will be compared.

var object1 = new MyComplexObject(1, "A string", true);
var object2 = new MyComplexObject(2, "A different string", true);
var diff = object1.Diff(object2, ComparisonOptions.All | ComparisonOptions.IncludeList, x => x.Id, x => x.Name);
Assert.AreEqual(diff.Count, 0);

Comparing Unordered lists

If you wish to perform a diff that ignores the ordering of data in a collection/list, you can specify that behavior with a ComparisonOptions AllowCollectionsToBeOutOfOrder flag as well as the AllowEqualsOverride, as seen below.

var list1 = new List<int> { 1, 2, 3 };
var list2 = new List<int> { 1, 3, 2 };
var diff = list1.Diff(list2, ComparisonOptions.All | ComparisonOptions.AllowCollectionsToBeOutOfOrder | ComparisonOptions.AllowEqualsOverride);
Assert.AreEqual(diff.Count, 0);

Analyzing results

Viewing the results of a diff:

var diff = object1.Diff(object2);

foreach(var difference in diff)
{
  Console.Write($"Index: {difference.ArrayIndex}"); // when array elements differ in value
  Console.Write($"Delta: {difference.Delta}"); // when numbers, Dates, Timespans, strings differ in value
  Console.Write($"Left: {difference.LeftValue}"); // the left value being compared
  Console.Write($"Right: {difference.RightValue}"); // the right value being compared
  Console.Write($"Property name: {difference.Property}"); // the name of the field/property
  Console.Write($"Property type: {difference.PropertyType}"); // the type of the field/property
}

Scenarios supported

  • Circular references
  • Using TypeConverters to understand data types
  • Deltas on strings, DateTimes, TimeSpans, numeric types
  • Comparing arrays, collections, custom collections, dictionaries, hashtables
  • Comparing collections with different ordering
  • Complex objects, deep type inspection
  • Entity Framework objects
  • IEquatable support

Using with other libraries

Comparing the difference between the same object at different states, using AnyClone

using AnyDiff.Extensions;
using AnyClone;

var object1 = new MyComplexObject(1, "A string");
var object1Snapshot = object1.Clone();

var diff = object1.Diff(object1Snapshot);
Assert.AreEqual(diff.Count, 0);

// change something anywhere in the object tree
object1.Name = "A different string";

diff = object1.Diff(object1Snapshot);
Assert.AreEqual(diff.Count, 1);
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].