Giter Site home page Giter Site logo

diffo's Introduction

====== ###Deep compare two objects


DiffO library is specifically designed for ASP.NET MVC, containing a set of Html helpers for marking the differences in the view.

Its usage is very simple. All you have to do, is to inherit your models from DiffObject and call the CompareTo() method. Calling the method, will iterate through the objects properties and if it finds properties that also inherit DiffObject compares them as well.

void CompareTo<T>(this T current, T previous) where T : IDiffObject

###Html helpers:

List<object> GetListPropertyDiff<TModel, TKey>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TKey>> expression, DifferenceType type)

Use for list property. The type parameter specifies whether to get the added or removed items.

Example:

var removed = Html.GetListPropertyDiff(x => x.Items, DifferenceType.Removed)
 var added = Html.GetListPropertyDiff(x => x.Items, DifferenceType.Added)

string GetPropertyDiffStyle<TModel, TKey>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TKey>> expression);

Based on the difference type (modified, removed, added) calling this method will return a css specific style

Example:

<li style="@Html.GetPropertyDiffStyle(x => x.Name)">@Model.Name</li>

object GetPropertyDiffOldValue<TModel, TKey>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TKey>> expression);

If a certain property's value has been removed, call this method to get the old value.

Example:

<li style="@Html.GetPropertyDiffStyle(x => x.Name)">@(Model.Color ?? Html.GetPropertyDiffOldValue(x => x.Color))</li>

DifferenceType GetPropertyDiffType<TModel, TKey>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TKey>> expression);

Get the type of modification this property suffered, to create a custom style.

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.