Toastie.Extensions (2.2.1)

Published 2024-07-10 01:10:57 -07:00 by toastie_t0ast

Installation

dotnet nuget add source --name toastie_t0ast --username your_username --password your_token 
dotnet add package --source toastie_t0ast --version 2.2.1 Toastie.Extensions

About this package

Provides extension methods for common tasks.

Toastie.Extensions

Defines the following extension methods:

  • Array Extensions
    • Several wrappers for System.Array static methods.
  • Assembly Extensions
    • GetConcreteTypes: Gets all concrete types from the current assembly.
    • GetAbstractTypes: Gets all abstract types from the current assembly.
    • GetConcreteTypesOf: Gets the concrete types from the current assembly that derive from another type.
    • GetAbstractTypesOf: Gets the abstract types from the current assembly that derive from another type.
  • DateTimeOffset Extensions
    • StartOfDay: Gets the beginning of the day for the current DateTimeOffset object.
  • Enum Extensions
    • HasOneFlag: Checks if the current enum has at least one of the provided bit flags.
    • ToFlags: Flattens a collection of enums to a single enum value that contains all bit flags from the enums in the collection. It's the opposite of ToValues().
    • ToStrings: Creates a collection of human-readable strings of the current enum.
    • ToValues: Segregates bit flags into a collection of enum values of their own. It's the opposite of ToFlags().
    • ToggleFlag: Returns an enum with the provided bit flag set if it's not currently set, and vice-versa.
  • IEnumerable<T> Extensions
    • AtLeast: Checks if the current collection contains at least the specified amount of elements and exits early if it does.
    • ChunkBy: Splits a collection into a collection of collections based on the provided key selector.
    • ContainsOne: Checks if the current collection contains at least one element of a given collection.
    • ContainsSubcollection: Checks if the current collection contains all elements of a given collection.
    • MaxOrDefault: Returns the maximum value in a generic sequence or default if the sequence is empty.
    • MaxByOrDefault: Returns the maximum value in a generic sequence according to a specified key selector function or default if the sequence is empty.
    • MinOrDefault: Returns the minimum value in a generic sequence or default if the sequence is empty.
    • MinByOrDefault: Returns the minimum value in a generic sequence according to a specified key selector function or default if the sequence is empty.
    • NestedFill: Adds a sample object to the inner collections of a collection of collections until they all have the same length.
    • OrderAmount: Sorts the elements of a sequence in ascending order according to how many times they appear in the sequence.
    • OrderDescendingAmount: Sorts the elements of a sequence in descending order according to how many times they appear in the sequence.
    • OrderByAmount: Sorts the elements of a sequence in ascending order according to how many times the selected property appears in the sequence.
    • OrderByDescendingAmount: Sorts the elements of a sequence in descending order according to how many times the selected property appears in the sequence.
    • RandomElement: Gets a random element from the current collection.
    • Split: Splits the current collection into multiple collections based on the specified separator.
    • Tap: Executes an action on every element of the collection. Due to poor performance, this method should only be used for testing purposes!
    • Unique: Gets the symetric difference between all elements in the current and specified collections.
    • When: Fluent version of an if statement.
    • WhenAllAsync: Awaits all tasks in the current IEnumerable<Task> and returns when all of them have completed.
    • WhenAnyAsync: Awaits all tasks in the current IEnumerable<Task> and returns when any of them have completed.
    • ZipOrDefault: Produces a sequence of tuples with elements from the two specified sequences. If one of the sequences is larger than the other, the exceeding elements from the larger sequence get paired with default values.
    • A variety of "To" methods:
      • ToConcurrentDictionary
      • ToQueue
      • ToConcurrentQueue
      • ToImmutableQueue
      • ToPriorityQueue
      • ToStack
      • ToConcurrentStack
      • ToImmutableStack
  • IReadOnlyList<T> Extensions
    • IndexOf: Get the index of the first element that matches a predicate.
    • LastIndexOf: Get the index of the last element that matches a predicate.
    • TryGetValue: safely get an element from the collection, or default(T) if it fails.
  • List<T> Extensions
    • AsSpan: Gets the current list as a Span<T> object.
    • AsReadOnlySpan: Gets the current list as a ReadOnlySpan<T> object.
  • Object Extensions
    • EqualsAny: Checks whether the current object equals any of the specified objects.
  • ReadOnlySpan<T> Extensions
    • AsEnumerable: Enumerates the current span.
  • Span<T> Extensions
    • AsEnumerable: Enumerates the current span.
    • Rotate: Rotates a span from a starting position by the specified amount of indices.
  • String and ReadOnlySpan<char> Extensions
    • Contains: Checks if the current string occurs within at least one of the entries in the provided collection.
    • EndsWith: Checks whether the end of the current string matches any string stored in the provided collection.
    • Equals: Checks whether the current string is equal to any of the provided strings.
    • FirstOccurrenceOf: Returns the "Nth" index of the provided character.
    • GetDigits: Returns a string with all digits present in this string.
    • HasFirstWordOf: Checks if the current string and the provided string contain the same first word.
    • LastOccurrenceOf: Returns the last "Nth" index of the provided character.
    • MaxElementLength: Get the length of the longest string of the current collection.
    • MaxLength: Truncates the string to the maximum specified length.
    • Occurrences: Gets the amount of occurences of a given character in the current string.
    • StartsWith: Checks whether the beginning of the current string matches any string stored in the provided collection.
    • ToSnakeCase: Converts the current string to the snake_case format.
    • ToTitleCase: Converts the current string to the Title Case format.
  • StringBuilder Extensions
    • ReplaceAll: Replaces all instances of a substring with another substring, even if the new substring is a substring of the old substring.
    • ToStringAndClear: Returns the string value of the current builder and clears the builder.
Details
NuGet
2024-07-10 01:10:57 -07:00
5
Toastie
64 KiB
Assets (2)
Versions (11) View all
2.3.2 2024-07-10
2.3.1 2024-07-10
2.3.0 2024-07-10
2.2.1 2024-07-10
2.2.0 2024-07-10