Pargoon.Extensions.Linq
1.0.0
deprecated
See the version list below for details.
dotnet add package Pargoon.Extensions.Linq --version 1.0.0
NuGet\Install-Package Pargoon.Extensions.Linq -Version 1.0.0
<PackageReference Include="Pargoon.Extensions.Linq" Version="1.0.0" />
<PackageVersion Include="Pargoon.Extensions.Linq" Version="1.0.0" />
<PackageReference Include="Pargoon.Extensions.Linq" />
paket add Pargoon.Extensions.Linq --version 1.0.0
#r "nuget: Pargoon.Extensions.Linq, 1.0.0"
#:package Pargoon.Extensions.Linq@1.0.0
#addin nuget:?package=Pargoon.Extensions.Linq&version=1.0.0
#tool nuget:?package=Pargoon.Extensions.Linq&version=1.0.0
Pargoon.Extensions.Linq
Overview
Pargoon.Extensions.Linq is a C# library that provides a set of extension methods for enhancing IQueryable<T> and IEnumerable<T> operations. These extensions focus on conditional filtering (WhereIf) and dynamic sorting (Sorting), allowing developers to build more flexible and maintainable LINQ queries.
Features
- Conditional Filtering: Easily apply filters to queries based on runtime conditions.
- Dynamic Sorting: Sort collections dynamically based on property names and sort directions, with support for multiple sorting criteria.
- Supports Both
IQueryable<T>andIEnumerable<T>: Although the library is optimized forIQueryable<T>, it also provides fallback support forIEnumerable<T>by converting toIQueryable<T>.
Installation
To use the Pargoon.Extensions.Linq library, simply include the source file in your project or compile the code into a DLL and reference it in your project.
Usage
1. Conditional Filtering (WhereIf)
The WhereIf extension method allows you to apply a filter to a query only if a specified condition is true.
using Pargoon.Extensions.Linq;
// Applying a filter conditionally
var filteredData = data.WhereIf(isActive, x => x.IsActive);
isActive: A boolean condition.x => x.IsActive: The predicate to apply ifisActiveis true.
2. Dynamic Sorting (Sorting)
The Sorting extension methods provide a way to sort collections based on property names and sort directions at runtime.
Single Property Sorting
using Pargoon.Extensions.Linq;
var sortedData = data.Sorting("PropertyName", SortDirection.Asc);
PropertyName: The name of the property to sort by.SortDirection.Asc: Sort direction (ascending or descending).
Multiple Property Sorting
using Pargoon.Extensions.Linq;
var sortItems = new List<SortItem>
{
new SortItem { PropertyName = "FirstName", Direction = SortDirection.Asc },
new SortItem { PropertyName = "LastName", Direction = SortDirection.Desc }
};
var sortedData = data.Sorting(sortItems);
sortItems: A list ofSortItemobjects specifying the properties and directions to sort by.
3. Custom Comparers
If you need to use a custom comparer for sorting, you can pass it as an optional parameter:
using Pargoon.Extensions.Linq;
var sortedData = data.Sorting("PropertyName", SortDirection.Asc, comparer: new CustomComparer());
CustomComparer: Your customIComparer<object>implementation.
Example
Here's a complete example of using Pargoon.Extensions.Linq in a typical scenario:
using Pargoon.Extensions.Linq;
var isActive = true;
var sortItems = new List<SortItem>
{
new SortItem { PropertyName = "FirstName", Direction = SortDirection.Asc },
new SortItem { PropertyName = "LastName", Direction = SortDirection.Desc }
};
var query = dbContext.Users
.WhereIf(isActive, x => x.IsActive)
.Sorting(sortItems);
var result = query.ToList();
In this example:
- Users are filtered by
IsActiveonly ifisActiveistrue. - The filtered results are then sorted by
FirstNamein ascending order andLastNamein descending order.
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue or submit a pull request.
License
This library is licensed under the MIT License. See the LICENSE file for more details.
With Pargoon.Extensions.Linq, you can build more dynamic and flexible LINQ queries, improving both the readability and maintainability of your code.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- Pargoon.Core (>= 1.2.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Pargoon.Extensions.Linq:
| Package | Downloads |
|---|---|
|
Noyan.ShadMessage.ApiContracts
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.