1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-25 02:58:47 +00:00
Extension methods on crack.
Go to file
2024-02-12 09:34:35 +00:00
.config Add Stryker tool 2022-02-22 14:39:54 +00:00
.github Merge branch 'main' into release/4.0.0 2024-02-12 09:34:35 +00:00
docfx_project refactor!: remove X10D.Unity + associated projects/workflows (#86) 2023-09-13 00:25:04 +01:00
tools build: target .NET 8 (#88) 2023-11-14 16:49:53 +00:00
X10D fix: revert changes by merge conflict from #89 2024-01-06 14:31:47 +00:00
X10D.Hosting build: target .NET 8 (#88) 2023-11-14 16:49:53 +00:00
X10D.Tests fix(tests): add test to fix coverage on DateOnly.Deconstruct 2024-02-12 02:35:17 +00:00
_config.yml Set theme jekyll-theme-slate 2020-04-26 14:23:54 +01:00
.editorconfig Suppress CA1805 in .editorconfig 2022-11-29 17:17:28 +00:00
.gitignore #30 Use .NET Core gitignore 2021-03-03 14:32:00 +00:00
branding_Banner.png [ci skip] docs(style): update branding 2023-03-31 22:19:41 +01:00
branding_Icon.png style: update branding 2023-03-31 22:22:52 +01:00
branding_Social.png [ci skip] style: add social embed branding export 2023-03-31 22:30:25 +01:00
CHANGELOG.md refactor!: remove Span<T>.Replace for .NET 8 (#88) 2023-11-14 16:55:12 +00:00
CONTRIBUTING.md [ci skip] docs: add conventional commit to contrib guidelines 2023-04-12 12:47:32 +01:00
Directory.Build.props chore: don't share TargetFrameworks in build props 2023-08-28 13:04:16 +01:00
global.json build: target .NET 8 (#88) 2023-11-14 16:49:53 +00:00
LICENSE.md [ci skip] docs: update copyright year in LICENSE.md 2023-03-31 15:12:59 +01:00
README.md Merge branch 'main' into release/4.0.0 2024-02-12 01:50:34 +00:00
X10D.sln chore: add global.json to sln 2023-11-14 16:48:48 +00:00

GitHub Workflow Status GitHub Issues Coverage NuGet Downloads Stable Version Nightly Version MIT License

About

X10D (pronounced extend), is a .NET package that provides extension methods for numerous types. The purpose of this library is to simplify a codebase by reducing the need for repeated code when performing common operations. Simplify your codebase. Take advantage of .NET. Use extension methods.

(I'm also dogfooding this library, so there's that.)

What are extension methods?

Extension methods are a clever .NET feature that augment existing types with new functionality. They are defined as static methods in a static class, and are called as if they were instance methods on the type they are extending. Take, for example, the following code:

public static class Program
{
    public static void Main()
    {
        string str = "Hello, world!";
        Console.WriteLine(str.Reverse());
    }
}

public static class StringExtensions
{
    public static string Reverse(this string str)
    {
        char[] chars = str.ToCharArray();
        Array.Reverse(chars);
        return new string(chars);
    }
}

This will print !dlrow ,olleH to the console. The Reverse method is defined in the StringExtensions class, yet is called as if it were an instance method on the str variable, even though it's not.

Why use extension methods?

Extension methods were introduced when LINQ was added to .NET. LINQ is a set of extension methods that provide a way to query, filter, and transform data. If you were to access LINQ's methods statically, you would have to write code like this:

public static class Program
{
    public static void Main()
    {
        int[] numbers = { 1, 2, 3, 4, 5 };
        IEnumerable<int> evenNumbers = Enumerable.Where(numbers, x => x % 2 == 0);
        IEnumerable<int> doubledNumbers = Enumerable.Select(evenNumbers, x => x * 2);
        int sum = Enumerable.Sum(doubledNumbers);
        Console.WriteLine(sum);
    }
}

And if you wanted to one-line this, you'd have to write this:

public static class Program
{
    public static void Main()
    {
        int[] numbers = { 1, 2, 3, 4, 5 };
        Console.WriteLine(Enumerable.Sum(Enumerable.Select(Enumerable.Where(numbers, x => x % 2 == 0), x => x * 2)));
    }
}

This is a lot of code to write, and it's not very readable. The nested method calls make it incredibly difficult to follow. However, because LINQ is implemented as extension methods, you can write the following code instead:

public static class Program
{
    public static void Main()
    {
        int[] numbers = { 1, 2, 3, 4, 5 };
        Console.WriteLine(numbers.Where(x => x % 2 == 0).Select(x => x * 2).Sum());
    }
}

Because the methods are called as if they were instance methods on IEnumerable<T>, they can be chained together, making the code much more readable.

X10D aims to provide these same benefits as LINQ, but for dozens of other types and for countless other use cases. See the documentation for a complete breakdown of what's available.

Installation

NuGet installation

Install-Package X10D -Version 4.0.0

Manual installation

Download the latest release from this repository and adding a direct assembly reference for your chosen platform.

Documentation

Documentation and the API reference is available at https://oliverbooth.github.io/X10D/index.html. I'm sorry this took so long to get up and running. DocFX will be the death of me.

Contributing

Contributions are welcome. See CONTRIBUTING.md.

License

X10D is released under the MIT License. See here for more details.