C# Get SQL parameter

Date: 2020-09-04
public static string GetSqlParam(object value)
{
	if (value == null) return "NULL";
	if (value is bool b) return b ? "1" : "0"; // OR: SQL dialect: TRUE, FALSE
	if (value is Enum) return ((int)value).ToString();
	if (IsNumeric(value.GetType())) return value.ToString();
	if (value is DateTime d) return $"'{d.ToString("s", System.Globalization.CultureInfo.InvariantCulture)}'";
	return "'" + value.ToString().Replace("'", "''") + "'";
}

IsNumeric implementation: https://solidt.eu/site/c-isnumeric/

40150cookie-checkC# Get SQL parameter