Skip to content

jeduardocosta/structure-comparer

Repository files navigation

Structure Comparer

Build status Coverage Status Nuget version Nuget downloads

Available on NuGet as well: https://www.nuget.org/packages/StructureComparer

###Description

A .NET library that it allows for comparison of primitive, value and enum types. It can be used to ensure the equality between entities.

###Example Usage###

Use StructureComparer static class and the Compare method to do comparisons.

StructureComparer.Compare

Example 1 ( Check the equality using object types )####

var customer = new Customer();
var customerDto = new CustomerDTO();

var result = StructureComparer.Compare(typeof(customer), typeof(customerDto));

Example 2 ( Check the equality using generics )####

var result = StructureComparer.Compare<Customer, CustomerDTO>();

Comparison Result

The StructureComparisonResult class contains the result of comparison between entry types.

  • AreEqual ( compared objects are equal? )
  • DifferencesString ( result with the differences found ) - Example:
Failed to validate structures. Type 1: 'Int32', Type 2: 'Int16'. Property name: 'Id'
Failed to validate structures. Type 1: 'FakeEnum', Type 2: 'FakeEnumDifferentNames'. Property name: 'Enum'
Failed to validate structures. Type 1: 'FakeEnum', Type 2: 'FakeEnumDifferentNames'. Reason: divergent enum names. Property name: 'Enum' from 'FakeClass3' from 'FakeClass2'
Failed to validate structures. Type 1: 'FakeClass1', Type 2: 'FakeClass1'. Reason: property name 'FullName' was not found in type 'FakeClass1'

About

Structure comparison (primitive and complex type, enums)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages