<commit_before># NetSort

[![Build status](https://ci.appveyor.com/api/projects/status/qe0cobkgt70jr2bu/branch/master?svg=true)](https://ci.appveyor.com/project/philip-barrasso/netsort/branch/master) ![#](https://img.shields.io/nuget/v/NetSort.svg)

# Example

## Sort the response of an HTTP GET for people by their age

Class to be sorted
```
public class Person
{
    [Sortable("age")]
    public int Age { get; set; }

    public string Name { get; set; }
}
```

Controller (dotnet core)
```
[Route("api/v1/people")]
public class PeopleController : Controller
{
    private ISortKeyValidator _sortKeyValidator;

    public PeopleController(ISortKeyValidator sortKeyValidator)
    {
        _sortKeyValidator = sortKeyValidator;
    }

    [HttpGet]
    [Route("")]
    public async Task<IActionResult> GetPeople([FromQuery]string sortBy)
    {
        if (_sortKeyValidator.IsKeyValid<Person>(sortBy) == false)
        {
            return BadRequest($"{sortBy} is not a valid key for sorting people");
        }

        var people = new List<Person>()
        {
            new Person() { Age = 15, Name = "Bob" },
            new Person() { Age = 8, Name = "Steve" },
            new Person() { Age = 11, Name = "Sally" },
        };

        var sortedPeople = people.SortByKey(sortBy);
        return Ok(sortedPeople);
    }
}
```

200 Request ==> http://BASE_URL/api/v1/people?sortBy=age <br />
400 Request ==> http://BASE_URL/api/v1/people?sortBy=age3

# Installation

Nuget:

```
PM> Install-Package NetSort -Pre
```<commit_msg>updating readme per string sort direction<commit_after># NetSort

[![Build status](https://ci.appveyor.com/api/projects/status/qe0cobkgt70jr2bu/branch/master?svg=true)](https://ci.appveyor.com/project/philip-barrasso/netsort/branch/master) ![#](https://img.shields.io/nuget/v/NetSort.svg)

# Example

## Sort the response of an HTTP GET for people by their age

Class to be sorted
```
public class Person
{
    [Sortable("age")]
    public int Age { get; set; }

    public string Name { get; set; }
}
```

Controller (dotnet core)
```
[Route("api/v1/people")]
public class PeopleController : Controller
{
    private ISortKeyValidator _sortKeyValidator;

    public PeopleController(ISortKeyValidator sortKeyValidator)
    {
        _sortKeyValidator = sortKeyValidator;
    }

    [HttpGet]
    [Route("")]
    public async Task<IActionResult> GetPeople([FromQuery]string sortBy, [FromQuery]string sortDir = null)
    {
        if (_sortKeyValidator.IsKeyValid<Person>(sortBy) == false)
        {
            return BadRequest($"{sortBy} is not a valid key for sorting people");
        }

        var people = new List<Person>()
        {
            new Person() { Age = 15, Name = "Bob" },
            new Person() { Age = 8, Name = "Steve" },
            new Person() { Age = 11, Name = "Sally" },
        };

        if (sortDir != null)
        {
            return Ok(people.SortByKey(sortBy, sortDir));
        }

        return Ok(people.SortByKey(sortBy));
    }
}
```

200 Request ==> http://BASE_URL/api/v1/people?sortBy=age <br />
400 Request ==> http://BASE_URL/api/v1/people?sortBy=age3

# Installation

Nuget:

```
PM> Install-Package NetSort -Pre
```
{'fraction_non_alphanumeric': 0.14178871922717357, 'fraction_numerical': 0.011841695232159551, 'mean_word_length': 2.958076448828607, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 17, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1707045', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1029, 'n_words': 235}