-
Notifications
You must be signed in to change notification settings - Fork 1
01. Extensions Methods
David Shnayder edited this page Jan 4, 2024
·
4 revisions
public static Span<T> AsSpan<T>(this List<T> list)
public static ref TValue GetValueRefOrNullRef<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key) where TKey : notnull
public static ref TValue? GetValueRefOrAddDefault<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, out bool exists) where TKey : notnull
public static bool IsNullOrEmpty<T>(this ICollection<T>? collection)
public static T[] PureSort<T>(this T[] source, IComparer<T> comparer)
public static List<T> PureSort<T>(this IEnumerable<T> source, IComparer<T> comparer)
public static void RemoveDuplicates<T>(this List<T> list, out HashSet<T> hSet, IEqualityComparer<T>? comparer = null, bool isSorted = false)
public static void RemoveDuplicates<T>(this List<T> list, IEqualityComparer<T>? comparer = null, bool isSorted = false)
public static List<ArraySegment<T>> ChunkToSegments<T>(this T[] arr, int sizeOfChunk)
public static T[] ToArrayFast<T>(this HashSet<T> hashSet)// Formats the TimeSpan to show the largest unit with 2 decimal places and the unit name
// i.e 5.15 ms
public static string Format(this TimeSpan elapsed)
// Formats the TimeSpan to show each of the units as whole numbers with the corresponding unit names
// i.e 4d 3h 1m 57s
public static string ToRemainingDuration(this TimeSpan time)
// Formats the string to HHMM-dd-mmm-yy
public static string ToTimeStamp(this DateTime time)public static bool TryParseAsEnum<TEnum>(this string value, out TEnum result) where TEnum : struct, Enumpublic static ref char GetReference(this string text) // Returns actual reference to first character
public static bool IsNullOrEmpty(this string str)
public static bool IsNullOrWhiteSpace(this string str)
// Tried to convert the string to int32 using ascii, very efficient
public static bool TryConvertToInt32(this ReadOnlySpan<char> value, out int result)
// Concat - more efficient than + or interpolation
public static string Concat(this string value, ReadOnlySpan<char> suffix)
public static string ToTitle(this string str)
public static bool IsBinary(this string str)