MassChecker 1.0.1
dotnet add package MassChecker --version 1.0.1
NuGet\Install-Package MassChecker -Version 1.0.1
<PackageReference Include="MassChecker" Version="1.0.1" />
<PackageVersion Include="MassChecker" Version="1.0.1" />
<PackageReference Include="MassChecker" />
paket add MassChecker --version 1.0.1
#r "nuget: MassChecker, 1.0.1"
#:package MassChecker@1.0.1
#addin nuget:?package=MassChecker&version=1.0.1
#tool nuget:?package=MassChecker&version=1.0.1
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 | Versions 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. |
-
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.