A set of handy C# extension methods for objects, collections, strings, and streams to make your code cleaner and more expressive.
-
bool IsNull(this object obj)
✅ Returnstrueif the object isnull. -
bool IsNotNull(this object obj)
✅ Returnstrueif the object is not null.
-
void ForAll(this IEnumerable<T> source, Action<T> action)
Executesactionfor each element. Safe ifnull. -
void Times(this int count, Action<int> action)
Executesactioncounttimes. Safe ifnull. -
bool IsEmpty(this IEnumerable value)– Checks if empty -
bool IsNotEmpty(this IEnumerable value)– Checks if not empty -
bool IsNullOrEmpty(this IEnumerable value)– Checks null or empty -
bool IsNotNullOrEmpty(this IEnumerable value)– Checks not null and not empty -
T Pop<T>(this IList<T> source)– Returns last element and removes it -
T Shift<T>(this IList<T> source)– Returns first element and removes it -
void Unshift<T>(this IList<T> source, T toAdd)– Adds element at first position -
T AnyOne<T>(this IEnumerable<T> source)– Returns any element (throws if null/empty) -
bool None<T>(this IEnumerable<T> source, Func<T, bool> predicate = null)– Checks if no elements match the predicate
-
void EqualJsonCheck(this object obj, object toCompare)
Compares objects via JSON serialization and throws if unequal. -
bool IsEqualJson(this object obj, object toCompare)
Returnstrueif objects are equal via JSON.
string ExpEnv(this string text)– Shortcut forEnvironment.ExpandEnvironmentVariablesstring UseFormat(this string text, params string[] @params)– Usesstring.Formatfor placeholders
byte[] ToByteArray(this Stream stream)– Converts a Stream to a byte arrayStream ToStream(this byte[] byteArray)– Converts a byte array to a Stream