Coder Social home page Coder Social logo

luis-sousa-pinto / autocompare Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stevengilligan/autocompare

0.0 0.0 0.0 77 KB

AutoCompare is a simple library with the goal of making it effortless to compare two objects of the same type to generate the list of modified properties.

License: Other

C# 100.00%

autocompare's Introduction

Build status codecov.io

AutoCompare

What is AutoCompare?

AutoCompare is a simple library with the goal of making it effortless to compare two objects of the same type to generate the list of modified properties.

Why use AutoCompare?

The main goal of AutoCompare is making it easy to get differences between two objects of the same type. AutoCompare builds an Expression Tree the first time you compare a type so the first call is always slower. Once the Expression Tree is built and compiled, comparing two objects becomes extremely fast.

How to use AutoCompare in your project

Include AutoCompare in your project using NuGet

From the package manager console :

PM> Install-Package AutoCompare

Features

  • Works on any object type, and does deep compare (compares child objects)
  • Reflection is only used the first time a type is compared, successive calls are executing a compiled lambda and are extremely fast
  • Detects circular references so it won't throw a StackOverflowException if you have Parent.Child.Parent
  • Strongly typed fluent configuration using lambdas
  • Supports IEnumerable<> and IDictionary<,> properties, although some configuration might be necessary
  • Supports DI/IoC frameworks with the IComparerEngine interface, initialize using a new Engine()
  • Supports having multiple configuration for the same type, using separate IComparerEngine instances

Code examples

Compare two objects

var differences = AutoCompare.Comparer.Compare<MyObjectType>(objA, objB);

Configure properties that shouldn't be compared

AutoCompare.Comparer.Configure<MyObjectType>()
    .For(x => x.IgnoredProperty, x => x.Ignore()) 
    .Ignore(x => x.AnotherIgnoredProperty); // Alternative way to ignore a property

Configure a IEnumerable (array, list, hashmap, etc.) property to perform a deep compare. To deeply compare lists, you must specify the property to be used as a key or ID.

AutoCompare.Comparer.Configure<MyObjectType>()
    .For(x => x.ListProperty, x => x.MatchUsing(y => y.ID));

Precompile a type to make sure the first comparison is not slowed down by the compilation process

AutoCompare.Comparer.Configure<MyObjectType>()
	.Compile.Now(); // .Compile.Async() also available

Calling Configure<Type>() is optional and AutoCompare will default to comparing every public property.

Please note Configure<Type>() can only be called once per type, and must be called before executing Compare<Type>(), or it will throw an exception.

More examples can be found in AutoCompare.Tests

Licence

AutoCompare is Copyright © 2015 Steven Gilligan and other contributors under the Apache 2.0 license.

autocompare's People

Contributors

jklaus avatar stevengilligan avatar zacharybussey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.