Code Extensions

The CodeExtensions namespace contains extension methods that add additional functionality to existing .NET types without modifying their original source code. These methods are often used to simplify common programming tasks, improve code readability, and promote code reuse across .NET 6 and above projects. Extension methods in this namespace can be called as if they were instance methods on the types they extend, making them a powerful tool for enhancing the .NET framework's built-in classes.

Can be found at NuGet.org


  • CheckBoolean(this object value)
    Converts an object to a boolean value.
  • CheckBooleanNullable(this object value)
    Converts an object to a nullable boolean value.
  • CheckByte(this object value)
    Converts an object to a byte value.
  • CheckByteArray(this object value)
    Converts an object to a byte array.
  • CheckByteNullable(this object value)
    Converts an object to a nullable byte value.
  • CheckChar(this object value)
    Converts an object to a char value.
  • CheckCharArray(this object value)
    Converts an object to a char array.
  • CheckCharNullable(this object value)
    Converts an object to a nullable char value.
  • CheckDate(this object value)
    Converts an object to a DateTime value.
  • CheckDateNullable(this object value)
    Converts an object to a nullable DateTime value.
  • CheckDateTimeOffset(this object value)
    Converts an object to a DateTimeOffset value.
  • CheckDateTimeOffsetNullable(this object value)
    Converts an object to a nullable DateTimeOffset value.
  • CheckDecimal(this object value)
    Converts an object to a decimal value.
  • CheckDecimalNullable(this object value)
    Converts an object to a nullable decimal value.
  • CheckDouble(this object value)
    Converts an object to a double value.
  • CheckDoubleNullable(this object value)
    Converts an object to a nullable double value.
  • CheckFloat(this object value)
    Converts an object to a float value.
  • CheckFloatNullable(this object value)
    Converts an object to a nullable float value.
  • CheckGuid(this object value)
    Converts an object to a Guid, or Guid.Empty if conversion fails.
  • CheckGuidNullable(this object value)
    Converts an object to a nullable Guid.
  • CheckInt16(this object value)
    Converts an object to a short (Int16) value.
  • CheckInt16Nullable(this object value)
    Converts an object to a nullable short (Int16) value.
  • CheckInt32(this object value)
    Converts an object to an int (Int32) value.
  • CheckInt32Nullable(this object value)
    Converts an object to a nullable int (Int32) value.
  • CheckInt64(this object value)
    Converts an object to a long (Int64) value.
  • CheckInt64Nullable(this object value)
    Converts an object to a nullable long (Int64) value.
  • CheckInteger(this object value)
    Converts an object to an integer value.
  • CheckIntegerNullable(this object value)
    Converts an object to a nullable integer value.
  • CheckSByte(this object value)
    Converts an object to an sbyte value.
  • CheckSByteNullable(this object value)
    Converts an object to a nullable sbyte value.
  • CheckString(this object value, bool TrimAll = true)
    Converts an object to a string, optionally trimming whitespace.
  • CheckTimeSpan(this object value)
    Converts an object to a TimeSpan value.
  • CheckTimeSpanNullable(this object value)
    Converts an object to a nullable TimeSpan value.
  • CheckUInt16(this object value)
    Converts an object to a uint value.
  • CheckUInt16Nullable(this object value)
    Converts an object to a nullable uint value.
  • CheckUInt32(this object value)
    Converts an object to a ushort value.
  • CheckUInt32Nullable(this object value)
    Converts an object to a nullable ushort value.
  • CheckUInt64(this object value)
    Converts an object to a ulong value.
  • CheckUInt64Nullable(this object value)
    Converts an object to a nullable ulong value.
  • ConvertToSQLString(this string str, AssignQuotes assignQuotes)
    Converts a string to a SQL-safe string, optionally wrapping in single quotes.
  • DataTableToList<T>(this DataTable dt)
    Converts a DataTable to a list of objects of type T.
  • GetDataRow<T>(DataRow dr)
    Converts a DataRow to an object of type T.
  • NullIfEmpty(this string? value)
    Converts an empty string to null.
  • ToDataTable<T>(this List<T> items)
    Converts a list of objects to a DataTable.
  • ToEnum<T>(this string value)
    Converts a string to its enum equivalent.
  • ToInteger(this string value)
    Converts a string to an integer value.
  • ToLong(this string value)
    Converts a string to a long value.
  • ToShort(this string value)
    Converts a string to a short value.
An unhandled error has occurred. Reload 🗙