Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kurnakovv/priorityorder
PriorityOrder is an open source library that allows to order enumerable by priority.
https://github.com/kurnakovv/priorityorder
nuget nuget-package nuget-packages
Last synced: about 1 month ago
JSON representation
PriorityOrder is an open source library that allows to order enumerable by priority.
- Host: GitHub
- URL: https://github.com/kurnakovv/priorityorder
- Owner: kurnakovv
- License: mit
- Created: 2024-02-12T13:39:30.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-02-26T13:21:53.000Z (9 months ago)
- Last Synced: 2024-04-26T07:22:45.648Z (7 months ago)
- Topics: nuget, nuget-package, nuget-packages
- Language: C#
- Homepage:
- Size: 43.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: ReadMe.md
- License: LICENSE
Awesome Lists containing this project
README
PriorityOrder
[![NuGet](https://img.shields.io/nuget/v/Kurnakov.PriorityOrder.svg)](https://www.nuget.org/packages/Kurnakov.PriorityOrder)
[![NuGet download](https://img.shields.io/nuget/dt/Kurnakov.PriorityOrder.svg)](https://www.nuget.org/packages/Kurnakov.PriorityOrder)
![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fgithub.com%kurnakovv%PriorityOrder&countColor=%23263759&style=flat)
[![Build/Test](https://github.com/kurnakovv/PriorityOrder/actions/workflows/build-test.yml/badge.svg)](https://github.com/kurnakovv/PriorityOrder/actions/workflows/build-test.yml)
[![MIT License](https://img.shields.io/github/license/kurnakovv/PriorityOrder?color=%230b0&style=flat)](https://github.com/kurnakovv/PriorityOrder/blob/main/LICENSE)
# Description
PriorityOrder is an open source library that allows to order enumerable by priority.# Install
```
dotnet add package Kurnakov.PriorityOrder
```# Idea
``` cs
using PriorityOrder;public class Employee
{
public string Name { get; set; }
public string Role { get; set; }
}var source = new List
{
new Employee() { Name = "Willow", Role = "Manager" },
new Employee() { Name = "Huxley", Role = "Programmer" },
new Employee() { Name = "Tom", Role = "Programmer" },
new Employee() { Name = "Sutton", Role = "Tester" },
new Employee() { Name = "Lev", Role = "HR" },
new Employee() { Name = "Max", Role = "Programmer" },
new Employee() { Name = "Bob", Role = "Manager" },
new Employee() { Name = "Jack", Role = "Tester" },
new Employee() { Name = "Ruby", Role = "Manager" },
new Employee() { Name = "Willow", Role = "Accountant" },
};// For example, you want to order employees by these specific priorities (not alphabetically).
var priorities = new List()
{
"Programmer",
"Tester",
"Manager",
// After "Manager" order doesn't matter anymore.
};
List result = source
.OrderByPriority(x => x.Role, priorities)
.ThenBy(x => x.Name) // Optional.
.ToList();// result:
// Role: 'Programmer', Name: 'Huxley'
// Role: 'Programmer', Name: 'Max'
// Role: 'Programmer', Name: 'Tom'
// Role: 'Tester', Name: 'Jack'
// Role: 'Tester', Name: 'Sutton'
// Role: 'Manager', Name: 'Bob'
// Role: 'Manager', Name: 'Ruby'
// Role: 'Manager', Name: 'Willow'
// Role: 'HR', Name: 'Lev'
// Role: 'Accountant', Name: 'Willow'
```
> Besides strings you can use enum's, numbers etc (more details you can read on [Wiki](https://github.com/kurnakovv/PriorityOrder/wiki))# StackOverflow
* [Order by property name (string)](https://stackoverflow.com/questions/12199668/in-c-what-is-the-best-way-to-sort-a-list-of-objects-by-a-string-property-and-g/78045482#78045482)
* [Order by property name (enum)](https://stackoverflow.com/questions/42550992/c-sharp-sort-list-by-enum/77618384#77618384)# Docs
You can look at the full docs on [Wiki](https://github.com/kurnakovv/PriorityOrder/wiki)
* [PriorityEnumerable.OrderByPriority(IEnumerable priorities)](https://github.com/kurnakovv/PriorityOrder/wiki/PriorityEnumerable.OrderByPriority(IEnumerable-priorities))
* [PriorityEnumerable.OrderByPriority(params[] priorities)](https://github.com/kurnakovv/PriorityOrder/wiki/PriorityEnumerable.OrderByPriority(params%5B%5D-priorities))# Give a star ⭐
I hope this library is useful for you, if so please give a star for this repository, thank you :)