GenericMatcher 1.2.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package GenericMatcher --version 1.2.0
                    
NuGet\Install-Package GenericMatcher -Version 1.2.0
                    
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="GenericMatcher" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GenericMatcher" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="GenericMatcher" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add GenericMatcher --version 1.2.0
                    
#r "nuget: GenericMatcher, 1.2.0"
                    
#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.
#:package GenericMatcher@1.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=GenericMatcher&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=GenericMatcher&version=1.2.0
                    
Install as a Cake Tool

GenericMatcher

A high-performance .NET library for configurable entity matching and relationship mapping.

Features

  • Generic type support for flexible entity matching
  • Multiple matching strategies with customizable criteria
  • Two-way relationship mapping
  • Tiered matching for complex matching scenarios
  • Support for strict and non-strict matching modes
  • High-performance frozen collections for optimal memory usage
  • Thread-safe operations
  • Fluent API design

Installation

Install via NuGet:

dotnet add package GenericMatcher

Quick Start

Here's a basic example of matching entities:

// Define your entity
public record Person(string Id, string Name, string Email);

// Create match definitions
public class EmailMatch : MatchDefinition<Person, MatchType, string>
{
    public override MatchType MatchType => MatchType.Email;
    public override Func<Person, string> Conversion => x => x.Email.ToLowerInvariant();
}

// Initialize matcher
var matcher = new EntityMatcher<Person, MatchType>(
    seedEntities,
    new[] { new EmailMatch() }
);

// Find matches
var matches = matcher.FindMatches(person, MatchType.Email);

Advanced Usage

Two-Way Dictionary Matching

// Create a two-way relationship map
var twoWayMap = matcher.CreateTwoWayMatchDictionary(
    otherEntities,
    MatchType.Email,
    MatchType.Name
);

// Access matched and unmatched results
var matchedFromA = twoWayMap.AToBMatchedResults.Value;
var unmatchedFromB = twoWayMap.BToAUnmatchedResults.Value;

Tiered Matching

var tieredResult = matcher.CreateTwoWayMatchDictionary(
    otherEntities,
    new[] { 
        new[] { MatchType.Email },
        new[] { MatchType.Name, MatchType.DateOfBirth }
    }
);

Strict Matching

// Throws exception if multiple matches are found
var strictMatches = matcher.CreateStrictTwoWayMatchDictionary(
    otherEntities,
    MatchType.Email
);

Performance

GenericMatcher is designed for high performance:

  • Uses frozen collections for immutable operations
  • Optimized dictionary lookups
  • Memory-efficient data structures
  • Thread-safe operations
  • Benchmarked using BenchmarkDotNet

Benchmark results for two-way dictionary matching:

Entity Count Mean Time Error StdDev Gen0 Gen1 Gen2 Allocated Memory
100 12.95 µs ±1.633 µs 0.090 µs 0.4730 - - 8.91 KB
1,000 156.83 µs ±15.867 µs 0.870 µs 4.3945 0.7324 - 84.14 KB
10,000 1,630.75 µs ±73.539 µs 4.031 µs 48.8281 39.0625 39.0625 577.64 KB
100,000 19,729.08 µs ±8,605.220 µs 471.681 µs 62.5000 62.5000 62.5000 5,548.95 KB

API Documentation

EntityMatcher<TEntity, TMatchType>

Core class for entity matching operations.

Methods
  • FindMatches(TEntity entity, params TMatchType[] matchTypes)
  • FindFirstMatchOrDefault(TEntity entity, params TMatchType[] matchTypes)
  • CreateTwoWayMatchDictionary(IEnumerable<TEntity> otherEntities, params TMatchType[] matchTypes)
  • CreateStrictTwoWayMatchDictionary(IEnumerable<TEntity> otherEntities, params TMatchType[] matchTypes)

MatchDefinition<TEntity, TMatchType, TProperty>

Base class for defining match criteria.

Properties
  • MatchType: The type of match this definition represents
  • Conversion: Function to convert entity to comparable property
  • IsSeeded: Indicates if the definition has been initialized with seed data

License

MIT License - See LICENSE file for details.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.
  • net9.0

    • 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.4.3-preview 562 1/15/2025
1.4.2-preview 85 1/9/2025
1.4.1-preview 116 1/2/2025
1.4.0-preview 95 1/2/2025
1.3.0-preview 93 1/2/2025
1.2.0 141 12/31/2024
1.1.0 131 12/31/2024
1.0.0 104 12/27/2024