Skip to content

Collection of extension method for the BCL to ease their usage.

License

Notifications You must be signed in to change notification settings

PlainBytes/PlainBytes.System.Extensions

Repository files navigation

System.Extensions

Collection of extension method for the BCL to ease their usage. Please feel free to submit bits that are not yet included.

GitHub Nuget CodeFactor GradeBuild Validation

Examples

String

     var stringValue = "text";

    _ = stringValue.IsNullOrEmpty();
    _ = stringValue.IsNullOrWhiteSpace();

    _ = stringValue.HasValue();
    _ = stringValue.HasActualValue();

    _ = "{0} {1}".FormatWith(1, 2);

Numeric types

    // Int, uint, long, ulong, byte
    var number = 123;

    _ = intValue.Clamp(0, 100);
    _ = intValue.ToBool(); // each type has its revers bool to number.

Double

    var doubleValue = 12.34;

    _ = doubleValue.Clamp(0, 100);
    _ = doubleValue.IsInfinity();
    _ = doubleValue.IsNegativeInfinity();
    _ = doubleValue.IsPositiveInfinity();
    _ = doubleValue.IsNaN();
    _ = doubleValue.IsEqual(34.12,tolerance: 0.1); //two NaNs are also evaluated as equals

Collection access

    var collection = new[] {1, 2, 3};
    
    _ = collection.HasIndex(4);
    _ = collection.AtIndexOrDefault(4);
    _ = collection.AtIndexOrFallback(4, -1);
    _ = collection.IsEmpty();

    var directory = new Dictionary<int, int>();

    _ = directory.AtKeyOrFallback(4, -1);

Iterators

    // Extensions for IList<T>, IEnumerable<T> and Enumerable

    var collection = new[] {1, 2, 3};

    collection.For((index, value) => {});
    collection.ForEach(value => {});

    _ = collection.SelectWithIndex((index, value) => value);
    _ = collection.SelectTypeOf<double>();

    var secondCollection = new[] {4, 5};

    _ = collection.Append(secondCollection);

Install

Package manger

Install-Package PlainBytes.System.Extensions

CLI

dotnet add package PlainBytes.System.Extensions

Target platform: .Net Standard 1.0 and above.

About

Collection of extension method for the BCL to ease their usage.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages