DotDiff 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package DotDiff --version 1.0.2                
NuGet\Install-Package DotDiff -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DotDiff" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotDiff --version 1.0.2                
#r "nuget: DotDiff, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DotDiff as a Cake Addin
#addin nuget:?package=DotDiff&version=1.0.2

// Install DotDiff as a Cake Tool
#tool nuget:?package=DotDiff&version=1.0.2                

DotDiff

Object comparison and audit library for .net

Examples:

Using Expressions

Using Attributes

Manually Adding KeyPairs

Json Serialization

<a name="expressions"></a>Expressions Examples

Create a new console application and install the following nuget package

Install-Package DotDiff

Create Class

public class User
{
    public string Email { get; set; }
    public string UserName { get; set; }
    public string Password { get; set; }
    public bool Enabled { get; set; }
    public long Id { get; set; }
    public DateTime LastLogin { get; set; }
}

For Xml serialization add the following line to your Program.cs main:

var user1 = new User{
    //set all properties here
};
var user2 = new User{
    //set all properties here
};

var xml = new XmlAuditBuilder<User>()
                .Audit(user1, user2)
                .Include(_ => _.Email)
                .Include(_ => _.Password)
                .Include(_ => _.UserName)
                .Include(_ => _.Id)
                .Include(_ => _.Enabled)
                .Include(_ => _.LastLogin)
                .Serialize();
            ForegroundColor = ConsoleColor.Green;
            WriteLine(xml);

<a name="attributes"></a>Attributes Examples

Properties annotated with [Audit] attributes will be tracked for auditing by default. Create a new console application and install the following nuget package

Install-Package DotDiff

Create Class

public class User
{
    [Audit]
    public string Email { get; set; }
    public string UserName { get; set; }
}

For Xml serialization add the following line to your Program.cs main:

var user1 = new User{
    Email = "m1@domain1.com",
    UserName = "user1"
};
var user2 = new User{
    Email = "m2@domain2.com",
    UserName = "user2"
};

var xml = new XmlAuditBuilder<User>()
                .Audit(user1, user2)
                .Serialize();
            ForegroundColor = ConsoleColor.Green;
            WriteLine(xml);

The result will include the email values by default:

<ArrayOfAuditPair>
  <AuditPair>
    <Key>Email</Key>
    <OldValue>m1@domain1.com</OldValue>
    <NewValue>m2@domain2.com</NewValue>
  </AuditPair>
</ArrayOfAuditPair>

<a name="keypairs"></a>Key Pairs Example

For manually added attributes you can use the auditpair overload:

    var xml = new XmlAuditBuilder<User>()
                .Audit(user1, user2)
                .Include(_ => _.Id)
                .Include(
                    new AuditPair{
                        Key = "OtherAttribute123",
                        OldValue = "any value",
                        NewValue = null //or any other value if needed  
                    }
                )
                .Serialize();
<a name="json"></a>Json Example

For Json serialization add the following line to your Program.cs main: all above examples applies just replace XmlAuditBuilder with JsonAuditBuilder

var user1 = new User{
    //set all properties here
};
var user2 = new User{
    //set all properties here
};

var json = new JsonAuditBuilder<User>()
                .Audit(user1, user2)
                .Include(_ => _.Email)
                .Include(_ => _.Password)
                .Include(_ => _.UserName)
                .Include(_ => _.Id)
                .Include(_ => _.Enabled)
                .Include(_ => _.LastLogin)
                .Serialize();
            ForegroundColor = ConsoleColor.Green;
            WriteLine(json);

Future work:

  • collections
  • nested properties and classes
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has 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.

Version Downloads Last updated
1.0.3 417 10/31/2021
1.0.2 394 9/11/2021
1.0.1 1,007 7/2/2017
1.0.0 957 6/26/2017