namespace LaaProductionWeb.Data { using System; using System.Data.SqlClient; using System.Runtime.CompilerServices; internal static class FluentSQLExtensions { public static T EnsureNotNull(this T value, [CallerMemberName] string memberName = "") { value.ThrowIfNull(memberName); return value; } public static string EnsureNotNullOrWhiteSpace(this string value, [CallerMemberName] string memberName = "") { value.ThrowIfNullOrWhiteSpace(memberName); return value; } public static void ThrowIfNull(this T value, [CallerMemberName] string memberName = "") { if (value == null) { throw new ArgumentException($"{memberName} should not be null.", memberName); } } public static void ThrowIfNullOrWhiteSpace(this string value, [CallerMemberName] string memberName = "") { if (string.IsNullOrWhiteSpace(value)) { throw new ArgumentException($"{memberName} should not be null or white space.", memberName); } } internal static void OpenWithErrorHandling(this SqlConnection sqlConnection) { sqlConnection.ThrowIfNull(nameof(sqlConnection)); sqlConnection.FireInfoMessageEventOnUserErrors = true; sqlConnection.InfoMessage += SqlConnectionInfoMessage; sqlConnection.Open(); } internal static void SqlConnectionInfoMessage(object sender, SqlInfoMessageEventArgs e) { // TODO: Log error message to the caller or elsewhere. } } }