mx-pl.ExtendedTypes 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package mx-pl.ExtendedTypes --version 1.1.0
                    
NuGet\Install-Package mx-pl.ExtendedTypes -Version 1.1.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="mx-pl.ExtendedTypes" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="mx-pl.ExtendedTypes" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="mx-pl.ExtendedTypes" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add mx-pl.ExtendedTypes --version 1.1.0
                    
#r "nuget: mx-pl.ExtendedTypes, 1.1.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.
#:package mx-pl.ExtendedTypes@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=mx-pl.ExtendedTypes&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=mx-pl.ExtendedTypes&version=1.1.0
                    
Install as a Cake Tool

About This Project

A small C#/.NET library providing data type based utility methods—mainly for improved readability.

Motivation

The motivation for this library is two-fold:

Side-stepping the negation operator

Though the negation operator (!) is concise, it is also easy to miss and sometimes has to be put in places where it obstructs or does not align with the natural reading flow.

This library aims to provide extension methods which improve the readability and straightforwardness of such statements—and in some cases there conciseness, too.

More concise string manipulation

The C# string class comes pre-equipped with a variety of useful methods. However, invoking some of them requires rather roundabout statements (e.g. checking whether a string is empty).

This library provides some extension methods to simplify their usage.

Features

Boolean

This package provides a straightforward way to toggle (i.e. negate the value of) a boolean variable.

// Let's define a bool variable and set it to true.
var myBool = true; 
Toggle()

The extension method Toggle() negates the value of the instance without returning anything.

// Value of 'myBool' is 'true'.
myBool.Toggle();
// Value of 'myBool' is 'false'.
Toggled()

The extension method Toggled() returns the negated value but does not change the variable itself.

// Value of 'myBool' is 'true'.
var result = myBool.Toggled();
// Value of 'myBool' is still 'true'.
// Value of 'result' is 'false'.
Not()

The extension method Not() is simply an alias for Toggled() mirroring its behaviour.

// Value of 'myBool' is 'true'.
var result = myBool.Not();
// Value of 'myBool' is still 'true'.
// Value of 'result' is 'false'.

String

This library provides a concise way for checking whether a string is null or empty.

// Suppose we have a string variable.
var myString = "foo"; 
IsNullOrEmpty() and IsNullOrWhiteSpace()

If one wants to check whether a string is null, empty or only consisting of white-space characters, the C# string class does already provide methods for that: IsNullOrEmpty() and IsNullOrWhiteSpace().

This library, however, offers these build-in methods as extension methods.

// Conventionally, one would check whether the string is empty (or whitespace) like this:
string.IsNullOrEmpty(myString);
string.IsNullOrWhiteSpace(myString);

// Using this library's extension methods the statement looks like that:
myString.IsNullOrEmpty();
myString.IsNullOrWhiteSpace();

// In each case a boolean value is returned to indicate the answer.

The newly provided methods mirror the behaviour of the pre-existing ones (in fact, internally, they just invoke them).

IsNotNullOrEmpty() and IsNotNullOrWhiteSpace()

Additionally, this library offers the negated versions of these methods.

// The extension methods ...
myString.IsNotNullOrEmpty();
myString.IsNotNullOrWhiteSpace();

// ... are equivalent to:
!string.IsNullOrEmpty(myString);
!string.IsNullOrWhiteSpace(myString);

// Again, a boolean value is returned to indicate the result.

Feedback

Please note: I am a hobby programmer, so the way this library is implemented might not adhere to professional standards. I cannot guarantee it is behaving as intended, and am not actively maintaining it.

Nevertheless, if you have any suggestions, corrections or ideas, I would appreciate your feedback. Please leave a post in the Discussions or open an Issue over on GitHub.

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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.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.2.0 219 2/6/2024
1.1.0 239 1/6/2024
1.0.0 213 12/18/2023