Skip to content
Adrian Gabor edited this page Nov 17, 2021 · 18 revisions

ExtensionsDotNet makes working in .NET more productive by providing simple extension methods to perform common tasks. Many of these extension methods map to existing .NET functions hidden away in a namespace.

The library is written against .NET Standard 2.0 and will work in your .NET 5/6, .NET Core, .NET Framework, and Xamarin apps.

In order to check whether a string is null or empty you may write code like this:

public IEnumerable<Bicycle> Get(string connectionString)
{
    if (connectionString == null || connectionString == "")
        throw new ArgumentNullException(nameof(connectionString));
}

.NET offers a helper method...

public IEnumerable<Bicycle> Get(string connectionString)
{
    if (string.IsNullOrEmpty(connectionString))
        throw new ArgumentNullException(nameof(connectionString));
}

The problem is you have to remember that the helper method exists and how to access it. That's a lot to remember. Wouldn't it be easier if you took any instance of a string and these helper methods were available to you by pressing the dot after your object? That's were ExtensionsDotNet comes in.

Using the ExtensionsDoNet IsNullOrEmptyExt extension method, you could rewrite the code above as follows:

public IEnumerable<Bicycle> Get(string connectionString)
{
    if (connectionString.IsNullOrEmptyExt())
        throw new ArgumentNullException(nameof(connectionString));
}

No longer do you need to remember what helper methods are available and where they are located. Just hit the dot after your object and see a list of extensions available to you. All ExtensionsDotNet methods end in Ext. Some are original methods that simplify a common task, and some are maps to existing .NET functions.

One of the advantages of ExtensionsDotNet is fluency, the extensions can be changed together resulting in cleaner code in fewer lines. For example, if you wanted to take a plain text password, compute its SHA512 byte array, convert it to a base64 string, and output it to the console window, you can accomplish that with one line of code, like this:

string pass = "Passw0rd###";
pass.ComputeHash512Ext().ToBase64StringExt().WriteLineToConsoleExt();

To get started, visit the Setup page.

Clone this wiki locally