Skip to content

pylypeiev/CSharpExtensionMethods.MinimalPack

Repository files navigation

C# Extension Methods

Minimal Pack

#My C# Extension methods for collections and POCO objects. Enjoy! 💥

NuGet version

NuGet version

Table of Contents:

Collections extension methods

POCO extension methods

Collections extension methods

Array extension methods:

  • Clear - Sets a range of elements in an array to the default value of each element type.
  • Join - Concatenates the elements of an object array, using the specified separator between each element
  • ToArrayString - A simple string representation of an array(regular, 2d, jagged)

Dictionary extension methods:

  • AddIfNotContainsKey - Add an element with provided key to dictionary if this key is not exist yet
  • AddOrUpdate - Add an element with provided key to dictionary, if this key is exist - update value
  • ToTuple - Convert this dictionary to list of Tuples, where item1 is key and item2 is a value from this dictionary
  • GetValueOrDefault - Get an element with provided key if this key is exist, otherwise default value

ICollection extension methods:

  • AddIfNotContains - Add an element to the end of the collection if this value is not exist yet
  • AddRange - Adds the elements of the specified Array to the end of the collection
  • IsNullOrEmpty - Check if collection is null or empty
  • RemoveRange - Removes a range of elements from collection

IEnumerable extension methods:

  • Append - Add the object top the end of IEnumerable
  • AreAllSame - Check if all elements in IEnumerable are equals
  • Concatenate - Concatenates the elements of an IEnumerable to 1 string
  • ForEach - Performs the specified action on each element of the IEnumerable
  • IsEmpty - Check if IEnumerable is empty
  • IsNotEmpty - Check if IEnumerable is not empty
  • IsNullOrEmpty - Check if IEnumerable is null or empty
  • Join - Concatenates the elements of an IEnumerable, using the specified separator between each element
  • Prepend - Add the object at the beginning of IEnumerable
  • Shuffle - Shuffle IEnumerable
  • PickRandom - Pick N random elements from IEnumerable
  • ThisOrEmpty - Safe foreach and more, returns an empty Enumerable if source is null

IList extension methods:

  • ChunkBy - Chunk a list to smaller lists with a maximum capacity of the chunk size
  • Clone - Clone an collection to new IList
  • Push - Adds an object to the collection and return this collection for fluent api

POCO extension methods:

ByteArray extension methods:

  • ToBase64String - Converts an byte array to its equivalent string representation that is encoded with base-64.

DateTime extension methods:

  • ToUnixTime - convert date to UNIX Epoch time format
  • TrimToDay - Trims the time components so that the precision of the resulting time is to the day

object extension methods:

  • IfNotNull - Perform action/function on the object if it not null
  • IsIn - Determines if an object is contained in a sequence
  • IsNotNull - Check if object is NOT null
  • IsNull - Check if object is null
  • ToStringSafe - like ToString of the object, but not crushes if the object is null
  • Try - Try to perform action/function on object
  • Yield - Wraps this object instance into an IEnumerable, consisting of a single item
  • DeepCopy - Deep copy of object using BinaryFormatter

string extension methods:

  • ToDateTime - Convert to DateTime
  • ToDecimal - Convert to decimal
  • ToDouble - Convert to double
  • ToFloat - Convert to float
  • ToInt - Convert to int
  • ToLong - Convert to long
  • ToByteArray - Converts a string into an byte array
  • DecodeBase64 - Decodes a string encoded in base-64
  • EncodeBase64 - Encodes a string to its equivalent string representation that is encoded in base-64
  • RemoveFirst - Remove the number of characters at the start of this string
  • RemoveFirstCharacter - Remove the first character of this string
  • RemoveLast - Remove the number of characters at the end of this string
  • RemoveLastCharacter - Remove the last character of this string
  • Reverse - Reverse the sequence of characters in this string
  • SurroundWith - Surround this string with some string
  • TrimSafe - Performs a trim only if the item is not null
  • ToLowerSafe - Performs ToLower() only if input is not null
  • ToLowerInvariantSafe - Performs ToLowerInvariant() only if input is not null
  • ToUpperSafe - Performs ToUpper() only if input is not null
  • ToUpperInvariantSafe - Performs ToUpperInvariant() only if input is not null
  • EndsWithIgnoreCase - Determines whether the end of this string matches the specified string
  • EqualsIgnoreCase - Determines whether two specified strings have the same value
  • IfNullThen - Determines if the string is null or whitespace if yes returns nullAlternateValue
  • IsNullOrEmpty - Indicates whether this string is null or an empty string
  • IsNullOrWhiteSpace - Indicates whether this string is null, empty, or consists only of white-space characters
  • NthIndexOf - Reports the index of matched string regards to occurrenceNum
  • OccurrenceNum - Reports the numbers of matches in this string
  • StartsWithIgnoreCase - Determines whether the beginning of this string matches the specified string
  • ContainsInvariantSafe - String.Contains with StringComparison parameter

char extension methods:

Exception extension methods:

About

C# Extension Methods. Minimal Pack

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages