MassChecker 1.0.1

dotnet add package MassChecker --version 1.0.1
                    
NuGet\Install-Package MassChecker -Version 1.0.1
                    
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="MassChecker" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MassChecker" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="MassChecker" />
                    
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 MassChecker --version 1.0.1
                    
#r "nuget: MassChecker, 1.0.1"
                    
#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 MassChecker@1.0.1
                    
#: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=MassChecker&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=MassChecker&version=1.0.1
                    
Install as a Cake Tool

MassChecker Documentation

Overview

MassChecker provides a flexible and powerful mechanism to apply complex filtering logic on collections of objects. It consists of two main components: MassCheckerBase<TItem, TFilter> and CheckerAttribute. This library allows you to define filters with multiple conditions in a clean and maintainable way. It's particularly useful in scenarios where you need to apply various filtering criteria based on user input or other dynamic data sources.

Getting Started

Installation

To use MassChecker, add it to your project as a dependency. If MassChecker is hosted on a package repository, such as NuGet, you can install it using the package manager console:

Install-Package MassChecker

Or, if you're using .NET CLI:

dotnet add package MassChecker

Basic Usage

To create a new filter, extend the MassCheckerBase<TItem, TFilter> class and decorate your filtering methods with the [Checker] attribute. Here's a simple example:

public class RoflanFilter : MassCheckerBase<RoflanDto, RoflanFilterDto>
{
    [Checker]
    private bool CheckNumber(RoflanDto roflanDto, RoflanFilterDto filterDto)
    {
        return filterDto.Number == null || roflanDto.Number == filterDto.Number;
    }

    [Checker]
    private bool CheckName(RoflanDto roflanDto, RoflanFilterDto filterDto)
    {
        return filterDto.Name == null || roflanDto.Name == filterDto.Name;
    }

    [Checker]
    private bool CheckDate(RoflanDto roflanDto, RoflanFilterDto filterDto)
    {
        return (filterDto.DateFrom == null && filterDto.DateTo == null) 
               || (roflanDto.Date >= filterDto.DateFrom && roflanDto.Date <= filterDto.DateTo);
    }
}

The MassCheckerBase class provides a method NeedItem that evaluates all checkers against a given item and filter combination, returning true if all checkers pass.

Dependency Injection (DI) Setup

To maintain high performance, it is recommended to register your filters with a DI container and resolve them as singletons. This approach ensures that the reflection-heavy constructor of MassCheckerBase is called only once. Here's an example of how you might register a filter in a .NET Core application using the default DI container:

public void ConfigureServices(IServiceCollection services)
{
    // Register your filters as singletons
    services.AddSingleton<RoflanFilter>();
}

Performance Considerations

Direct instantiation of filter classes derived from MassCheckerBase is discouraged due to the reflection used in their constructors. Instead, rely on DI containers to manage their lifecycle as singletons. This approach significantly mitigates the performance overhead and ensures that your application remains responsive.

Conclusion

MassChecker offers a robust solution for implementing complex filtering logic in .NET applications. By following the guidelines provided in this document, you can integrate MassChecker into your project and benefit from its powerful features while maintaining high performance.

For further details, issues, or contributions, please refer to the project repository on GitHub.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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.
  • net6.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.0.1 1,300 2/28/2024
1.0.0 130 2/28/2024