[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Some random C# extension methods I've found useful. Published as Ardalis.Extensions on Nuget.

License

Notifications You must be signed in to change notification settings

ardalis/Ardalis.Extensions

Repository files navigation

NuGet NuGet publish Ardalis.Extensions to nuget

Ardalis.Extensions

Some random C# extension methods I've found useful. Published as Ardalis.Extensions on Nuget.

Table of Contents

Installation

Just add a reference the the package and then anywhere you want to use the extensions, add the appropriate using statement.

dotnet add package Ardalis.Extensions

Usage

String Checks

IsNull() checks whether a given string is null.

// replace
if(someString is null)

// with
if(someString.IsNull())

IsNullOrEmpty() checks whether a given string is null or empty.

// replace
if(String.IsNullOrEmpty(someString))

// with
if(someString.IsNullOrEmpty())

IsNullOrWhiteSpace checks whether a given string is null or empty or consists of only whitespace characters.

// replace
if(String.IsNullOrWhiteSpace(someString))

// with
if(someString.IsNullOrWhiteSpace())

Conventions for Contributors

  • Extension methods are grouped into folders based on similar purpose.
  • Folder nesting should match class namespaces.
    • Ardalis.Extensions.Parsing
    • Ardalis.Extensions.Encoding.Base64
  • One extension method class per folder.
  • Extension methods classes should have an Extensions suffix.
  • Classes should be made partial.
  • One extension method per file.
  • Overloads should be placed in the same file.
  • File names should be the contained extension method's name.
  • Tests should be provided for each extension method and overload.
  • Test classes should have a Tests suffix.
  • Benchmark classe should have a Benchmarks suffix.

Benchmarks

To run all of the benchmarks, run the following command from the benchmarks project folder:

dotnet run -c Release

Roadmap

For now as I gather different useful extensions there is a single Ardalis.Extensions package available on NuGet. Once there are more than a few, I will most likely break up the extensions into separate individual NuGet packages (for example: Ardalis.StringExtensions? Ardalis.Extensions.Strings?) and then the original Ardalis.Extensions would become a meta-package that would pull in all of the separate smaller packages.