DotDiff 1.0.2
See the version list below for details.
dotnet add package DotDiff --version 1.0.2
NuGet\Install-Package DotDiff -Version 1.0.2
<PackageReference Include="DotDiff" Version="1.0.2" />
paket add DotDiff --version 1.0.2
#r "nuget: DotDiff, 1.0.2"
// 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:
<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 | Versions 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. |
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.