LinqFlex 1.0.0

dotnet add package LinqFlex --version 1.0.0                
NuGet\Install-Package LinqFlex -Version 1.0.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="LinqFlex" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add LinqFlex --version 1.0.0                
#r "nuget: LinqFlex, 1.0.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.
// Install LinqFlex as a Cake Addin
#addin nuget:?package=LinqFlex&version=1.0.0

// Install LinqFlex as a Cake Tool
#tool nuget:?package=LinqFlex&version=1.0.0                

LinqFlex

LinqFlex is a .NET library that enables dynamic ordering of IQueryable collections. It allows you to sort data dynamically at runtime based on property names or key selectors, providing greater flexibility in data manipulation.

Installation

You can install the LinqFlex package via NuGet Package Manager:

dotnet add package LinqFlex

Or via the NuGet Package Manager Console:

Install-Package LinqFlex

Usage

Key Selector Example You can order your data using a key selector expression.

using System.Linq;
using LinqFlex;

public class Example
{
    public void SortUsingKeySelector()
    {
        var data = new[]
        {
            new Person { Id = 1, Name = "Alice" },
            new Person { Id = 2, Name = "Bob" },
            new Person { Id = 3, Name = "Charlie" }
        }.AsQueryable();

        // Sort by Name in ascending order
        var sortedData = data.OrderBy(p => p.Name, true);

        // Sort by Name in descending order
        var sortedDataDesc = data.OrderBy(p => p.Name, false);
    }
}

public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
}

Property Name Example

You can also order your data using a property name string. This is useful when the property to sort by is determined at runtime.

using System.Linq;
using LinqFlex;

public class Example
{
    public void SortUsingPropertyName()
    {
        var data = new[]
        {
            new Person { Id = 1, Name = "Alice" },
            new Person { Id = 2, Name = "Bob" },
            new Person { Id = 3, Name = "Charlie" }
        }.AsQueryable();

        // Sort by Name in ascending order
        var sortedData = data.OrderBy("Name", true);

        // Sort by Name in descending order
        var sortedDataDesc = data.OrderBy("Name", false);
    }
}

public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
}

Chaining Multiple Sorts

You can chain multiple sorts using ThenBy to order your data by adding additional properties further.

using System.Linq;
using LinqFlex;

public class Example
{
    public void SortUsingMultipleProperties()
    {
        var data = new[]
        {
            new Person { Id = 1, Name = "Alice", Age = 25 },
            new Person { Id = 2, Name = "Alice", Age = 30 },
            new Person { Id = 3, Name = "Bob", Age = 20 },
            new Person { Id = 4, Name = "Bob", Age = 35 }
        }.AsQueryable();

        // Sort by Name in ascending order, then by Age in ascending order
        var sortedData = data.OrderBy(x => x.Name, true).ThenBy(p => p.Age);

        // Sort by Name in descending order, then by Age in ascending order
        var sortedDataDesc = data.OrderBy("Name", false).ThenBy(p => p.Age);
    }
}

public class Person
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int Age { get; set; }
}

License

This project is licensed under the MIT License.

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. 
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.0 108 6/7/2024