CompareNETObjects

repository·master·Indexed 22 days ago

https://github.com/gregfinzer/compare-net-objects

A library for performing deep comparisons of any two .NET objects using reflection. It identifies differences between objects, including private fields and properties, and supports various reporting formats. Compatible with .NET Framework 4.0+, .NET Standard 1.3, 2.0, and 2.1, including support for .NET 5, 6, 7, and 8.

Tokens
822
Snippets
1
Records
6
Agent score
28%

What's inside CompareNETObjects

  1. Configure comparison options

    master

    The library provides several configuration options to fine-tune how objects are compared. Key options include:

    • Collection Handling: IgnoreCollectionOrder (to compare lists of different lengths) and ignoring indexer comparisons.
    • Member Filtering: Ability to ignore specific members by name or wildcard, ignore types, or use interface member filtering.
    • String Comparison: Treat string.Empty and null as equal, ignore leading/trailing whitespace, and enable case-insensitive comparison.
    • Numeric/Date Precision: Ignore millisecond differences between DateTime or DateTimeOffset values, and set precision for double or decimal values.
  2. Compatibility and Supported Runtimes

    master

    CompareNETObjects supports a wide range of .NET runtimes through different .NET Standard builds:

    • .NET Framework: 4.0 and higher.
    • .NET Standard 1.3: Compatible with .NET Core 1.0, Mono 4.6, Xamarin.iOS 10.0, Xamarin.Mac 3.0, Xamarin.Android 7.0, and UWP 10.0.
    • .NET Standard 2.0: Compatible with .NET Core 2.0, Mono 5.4, Xamarin.iOS 10.14, Xamarin.Mac 3.8, Xamarin.Android 8.0, UWP 10.0.16299, and Unity 2018.1.
    • .NET Standard 2.1: Compatible with .NET 5, .NET 6, .NET 7, .NET 8, Mono 6.4, Xamarin.iOS 12.16, Xamarin.Mac 5.16, Xamarin.Android 10.0.
  3. Avoid StackOverflow when overriding Equals

    master

    In version 4.62 and later, the library uses object references instead of hash codes to track parents and children to avoid issues with overridden GetHashCode.

    Warning: If your project overrides Equals and you are using CompareNETObjects inside that implementation, you must set Config.UseHashCodeIdentifier = true to prevent a stack overflow.

  4. Limitations of CompareNETObjects

    master

    Be aware of the following constraints when using the library:

    • Custom Collections: Collections with non-integer indexers cannot be compared.
    • Private Members: Private properties and fields cannot be compared in .NET Core 1.3 (they are supported in .NET Core 2.0 and higher).
    • Collection Order: When using IgnoreCollectionOrder, the collection matching spec must be a simple type property on the class itself (it cannot be a field or property on a child/parent class).
    • COM Objects: COM objects are not supported directly. To compare them, wrap their properties in a .NET object or implement a custom comparer.
  5. Supported Types for Comparison

    master

    CompareNETObjects supports a broad range of types, including:

    • Primitives & Basics: String, Int, Boolean, Guid, Enum, SByte, etc.
    • Collections: Arrays (Single, Multi-Dimensional, Immutable), List, Dictionary, HashSet, IDictionary, IList, and more.
    • Data Structures: DataSet, DataTable, DataRow, DataColumn.
    • Date/Time: DateTime, DateTimeOffset, DateOnly (.NET Core 6.0+), TimeOnly (.NET Core 6.0+), TimeSpan.
    • Complex Types: Anonymous Types, Classes, Structs, Dynamic (Expando/Dynamic objects), and RuntimeType.
    • Other: URI, IPEndPoint, StringBuilder, and more.