namespace Common.Logic.Extensions.SQL { using System; using System.Data.SqlClient; public static class SQLExtensions { internal static T EnsureNotNull(this T value, String member) { value.ThrowIfNull(member); return value; } internal static String EnsureNotNullOrWhiteSpace(this String value, String member) { value.ThrowIfNullOrWhiteSpace(member); return value; } internal static void ThrowIfNull(this T value, String member) { if (value == null) { throw new ArgumentException($"{member} should not be null.", member); } } internal static void ThrowIfNullOrWhiteSpace(this String value, String member) { if (String.IsNullOrWhiteSpace(value)) { throw new ArgumentException($"{member} should not be null or white space.", member); } } internal static void OpenWithErrorHandling(this SqlConnection sqlConnection, Action errorCallback) { sqlConnection.ThrowIfNull(nameof(sqlConnection)); sqlConnection.FireInfoMessageEventOnUserErrors = true; if (errorCallback != null) { sqlConnection.InfoMessage += (_, args) => errorCallback(args.Message); } sqlConnection.Open(); } } }