diff --git a/src/GUI/Directory.Build.Props b/src/GUI/Directory.Build.Props index 388499e3a..bb354c6ab 100644 --- a/src/GUI/Directory.Build.Props +++ b/src/GUI/Directory.Build.Props @@ -9,7 +9,7 @@ - + all runtime; build; native; contentfiles; analyzers diff --git a/src/GUI/ErikEJ.EntityFrameworkCore.6.SqlServer.SqlQuery/DbContextExtensions.cs b/src/GUI/ErikEJ.EntityFrameworkCore.6.SqlServer.SqlQuery/DbContextExtensions.cs index 668b65676..4a1f8d8ac 100644 --- a/src/GUI/ErikEJ.EntityFrameworkCore.6.SqlServer.SqlQuery/DbContextExtensions.cs +++ b/src/GUI/ErikEJ.EntityFrameworkCore.6.SqlServer.SqlQuery/DbContextExtensions.cs @@ -38,10 +38,7 @@ public static class DbContextExtensions /// public static async Task> SqlQueryValueAsync(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) // where T : class { - if (db is null) - { - throw new ArgumentNullException(nameof(db)); - } + ArgumentNullException.ThrowIfNull(db); if (parameters is null) { @@ -79,10 +76,7 @@ public static async Task> SqlQueryValueAsync(this DbContext db, strin public static async Task> SqlQueryAsync(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) where T : class { - if (db is null) - { - throw new ArgumentNullException(nameof(db)); - } + ArgumentNullException.ThrowIfNull(db); return await SqlQueryInternalAsync(db, sql, parameters, cancellationToken).ConfigureAwait(false); } diff --git a/src/GUI/ErikEJ.EntityFrameworkCore.7.SqlServer.SqlQuery/DbContextExtensions.cs b/src/GUI/ErikEJ.EntityFrameworkCore.7.SqlServer.SqlQuery/DbContextExtensions.cs index daac48b60..0d0b4c8b4 100644 --- a/src/GUI/ErikEJ.EntityFrameworkCore.7.SqlServer.SqlQuery/DbContextExtensions.cs +++ b/src/GUI/ErikEJ.EntityFrameworkCore.7.SqlServer.SqlQuery/DbContextExtensions.cs @@ -13,7 +13,6 @@ namespace Microsoft.EntityFrameworkCore /// /// Useful extensions for DbContext. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Major Code Smell", "S4457:Parameter validation in \"async\"/\"await\" methods should be wrapped", Justification = "Broken analyzer?")] public static class DbContextExtensions { /// @@ -39,10 +38,7 @@ public static class DbContextExtensions public static async Task> SqlQueryAsync(this DbContext db, string sql, object[] parameters = null, CancellationToken cancellationToken = default) where T : class { - if (db is null) - { - throw new ArgumentNullException(nameof(db)); - } + ArgumentNullException.ThrowIfNull(db); return await SqlQueryInternalAsync(db, sql, parameters, cancellationToken).ConfigureAwait(false); } diff --git a/src/GUI/ErikEJ.EntityFrameworkCore.SqlServer.Dacpac/SqlSharpener/Model/Table.cs b/src/GUI/ErikEJ.EntityFrameworkCore.SqlServer.Dacpac/SqlSharpener/Model/Table.cs index 515bfda6f..44541bd85 100644 --- a/src/GUI/ErikEJ.EntityFrameworkCore.SqlServer.Dacpac/SqlSharpener/Model/Table.cs +++ b/src/GUI/ErikEJ.EntityFrameworkCore.SqlServer.Dacpac/SqlSharpener/Model/Table.cs @@ -30,10 +30,7 @@ public Table(string name, IEnumerable columns) /// The foreign keys. public Table(dac.TSqlObject tSqlObject) { - if (tSqlObject == null) - { - throw new ArgumentNullException(nameof(tSqlObject)); - } + ArgumentNullException.ThrowIfNull(tSqlObject); // Get the name. this.Name = tSqlObject.Name.Parts[tSqlObject.Name.Parts.Count - 1]; diff --git a/src/GUI/RevEng.Core.60/ColumnRemovingScaffoldingModelFactory.cs b/src/GUI/RevEng.Core.60/ColumnRemovingScaffoldingModelFactory.cs index 467fd648c..55e069a90 100644 --- a/src/GUI/RevEng.Core.60/ColumnRemovingScaffoldingModelFactory.cs +++ b/src/GUI/RevEng.Core.60/ColumnRemovingScaffoldingModelFactory.cs @@ -35,10 +35,7 @@ public ColumnRemovingScaffoldingModelFactory([NotNull] IOperationReporter report protected override EntityTypeBuilder VisitTable(ModelBuilder modelBuilder, DatabaseTable table) { - if (table is null) - { - throw new ArgumentNullException(nameof(table)); - } + ArgumentNullException.ThrowIfNull(table); string name; if (databaseType == DatabaseType.SQLServer || databaseType == DatabaseType.SQLServerDacpac) diff --git a/src/GUI/RevEng.Core.60/DbContextSplitter.cs b/src/GUI/RevEng.Core.60/DbContextSplitter.cs index 5404ea1fd..82577df7c 100644 --- a/src/GUI/RevEng.Core.60/DbContextSplitter.cs +++ b/src/GUI/RevEng.Core.60/DbContextSplitter.cs @@ -15,10 +15,7 @@ public static class DbContextSplitter // Adapted from https://github.com/lauxjpn/DbContextOnModelCreatingSplitter public static List Split(string dbContextPath, string configNamespace, bool supportNullable) { - if (dbContextPath == null) - { - throw new ArgumentNullException(nameof(dbContextPath)); - } + ArgumentNullException.ThrowIfNull(dbContextPath); var dbContextFilePath = Path.GetFullPath(dbContextPath); @@ -71,7 +68,7 @@ public static List Split(string dbContextPath, string configNamespace, b .Where(m => m.Value.Trim().StartsWith("entity", StringComparison.Ordinal)) .ToList(); - if (!statementsBlockMatches.Any()) + if (statementsBlockMatches.Count == 0) { return new List(); } diff --git a/src/GUI/RevEng.Core.60/Functions/SqlServerFunctionModelFactory.cs b/src/GUI/RevEng.Core.60/Functions/SqlServerFunctionModelFactory.cs index 1161f8e90..e48206dfe 100644 --- a/src/GUI/RevEng.Core.60/Functions/SqlServerFunctionModelFactory.cs +++ b/src/GUI/RevEng.Core.60/Functions/SqlServerFunctionModelFactory.cs @@ -45,10 +45,7 @@ public RoutineModel Create(string connectionString, ModuleModelFactoryOptions op protected override List> GetResultElementLists(SqlConnection connection, Routine module, bool multipleResults, bool useLegacyResultSetDiscovery) { - if (module is null) - { - throw new ArgumentNullException(nameof(module)); - } + ArgumentNullException.ThrowIfNull(module); using var dtResult = new DataTable(); var list = new List(); diff --git a/src/GUI/RevEng.Core.60/Functions/SqlServerFunctionScaffolder.cs b/src/GUI/RevEng.Core.60/Functions/SqlServerFunctionScaffolder.cs index f2dd65cb2..259ccaf15 100644 --- a/src/GUI/RevEng.Core.60/Functions/SqlServerFunctionScaffolder.cs +++ b/src/GUI/RevEng.Core.60/Functions/SqlServerFunctionScaffolder.cs @@ -28,15 +28,9 @@ protected override string WriteDbContextInterface(ModuleScaffolderOptions scaffo protected override string WriteDbContext(ModuleScaffolderOptions scaffolderOptions, RoutineModel model, List schemas) { - if (scaffolderOptions is null) - { - throw new ArgumentNullException(nameof(scaffolderOptions)); - } + ArgumentNullException.ThrowIfNull(scaffolderOptions); - if (model is null) - { - throw new ArgumentNullException(nameof(model)); - } + ArgumentNullException.ThrowIfNull(model); Sb = new IndentedStringBuilder(); @@ -143,7 +137,7 @@ private void GenerateFunctionStub(Routine function, RoutineModel model) var parameters = string.Empty; - if (function.Parameters.Any()) + if (function.Parameters.Count != 0) { parameters = string.Join(", ", paramStrings); } diff --git a/src/GUI/RevEng.Core.60/ReplacingCandidateNamingService.cs b/src/GUI/RevEng.Core.60/ReplacingCandidateNamingService.cs index 9877f097c..2b467b198 100644 --- a/src/GUI/RevEng.Core.60/ReplacingCandidateNamingService.cs +++ b/src/GUI/RevEng.Core.60/ReplacingCandidateNamingService.cs @@ -77,10 +77,7 @@ public override string GenerateCandidateIdentifier(DatabaseTable originalTable) public override string GenerateCandidateIdentifier(DatabaseColumn originalColumn) { - if (originalColumn is null) - { - throw new ArgumentNullException(nameof(originalColumn)); - } + ArgumentNullException.ThrowIfNull(originalColumn); var candidateStringBuilder = new StringBuilder(); diff --git a/src/GUI/RevEng.Core.60/ReverseEngineerRunner.cs b/src/GUI/RevEng.Core.60/ReverseEngineerRunner.cs index 5012419bc..c2d45bbea 100644 --- a/src/GUI/RevEng.Core.60/ReverseEngineerRunner.cs +++ b/src/GUI/RevEng.Core.60/ReverseEngineerRunner.cs @@ -219,7 +219,7 @@ public static ReverseEngineerResult GenerateFiles(ReverseEngineerCommandOptions public static void RetryFileWrite(string path, List finalLines) { - for (int i = 1; i <= 3; ++i) + for (int i = 1; i <= 4; ++i) { try { @@ -235,7 +235,7 @@ public static void RetryFileWrite(string path, List finalLines) public static void RetryFileWrite(string path, string finalText) { - for (int i = 1; i <= 3; ++i) + for (int i = 1; i <= 4; ++i) { try { diff --git a/src/GUI/RevEng.Core.60/Routines/SqlServerRoutineModelFactory.cs b/src/GUI/RevEng.Core.60/Routines/SqlServerRoutineModelFactory.cs index e61735f74..898d36316 100644 --- a/src/GUI/RevEng.Core.60/Routines/SqlServerRoutineModelFactory.cs +++ b/src/GUI/RevEng.Core.60/Routines/SqlServerRoutineModelFactory.cs @@ -23,10 +23,7 @@ public abstract class SqlServerRoutineModelFactory protected RoutineModel GetRoutines(string connectionString, ModuleModelFactoryOptions options) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } + ArgumentNullException.ThrowIfNull(options); SqlServerSqlTypeExtensions.UseDateOnlyTimeOnly = options.UseDateOnlyTimeOnly; @@ -56,7 +53,7 @@ protected RoutineModel GetRoutines(string connectionString, ModuleModelFactoryOp } #pragma warning restore CA2100 // Review SQL queries for security vulnerabilities - var allParameters = options.FullModel && found.Any() ? GetParameters(connection) : new Dictionary>(); + var allParameters = options.FullModel && found.Count != 0 ? GetParameters(connection) : new Dictionary>(); foreach (var foundModule in found) { @@ -136,7 +133,7 @@ protected RoutineModel GetRoutines(string connectionString, ModuleModelFactoryOp .Select(y => y.Key) .ToList(); - if (duplicates.Any()) + if (duplicates.Count != 0) { dupesFound = true; errors.Add($"Unable to scaffold {RoutineType} '{module.Schema}.{module.Name}' as it has duplicate result column names: '{duplicates[0]}'."); diff --git a/src/GUI/RevEng.Core.60/Routines/SqlServerRoutineScaffolder.cs b/src/GUI/RevEng.Core.60/Routines/SqlServerRoutineScaffolder.cs index 4e1c2070a..e1c2a63f7 100644 --- a/src/GUI/RevEng.Core.60/Routines/SqlServerRoutineScaffolder.cs +++ b/src/GUI/RevEng.Core.60/Routines/SqlServerRoutineScaffolder.cs @@ -105,10 +105,7 @@ public abstract class SqlServerRoutineScaffolder : IRoutineScaffolder protected SqlServerRoutineScaffolder([System.Diagnostics.CodeAnalysis.NotNull] ICSharpHelper code) { - if (code == null) - { - throw new ArgumentNullException(nameof(code)); - } + ArgumentNullException.ThrowIfNull(code); this.Code = code; } @@ -296,10 +293,7 @@ private static string GenerateUniqueName(Routine routine, RoutineModel model) private static Tuple GeneratePropertyName(string propertyName) { - if (propertyName == null) - { - throw new ArgumentNullException(nameof(propertyName)); - } + ArgumentNullException.ThrowIfNull(propertyName); return CreateIdentifier(propertyName); } diff --git a/src/GUI/RevEng.Core.60/ServiceProviderBuilder.cs b/src/GUI/RevEng.Core.60/ServiceProviderBuilder.cs index d72a6608b..d40480197 100644 --- a/src/GUI/RevEng.Core.60/ServiceProviderBuilder.cs +++ b/src/GUI/RevEng.Core.60/ServiceProviderBuilder.cs @@ -34,15 +34,9 @@ public static class ServiceProviderBuilder { public static IServiceCollection AddEfpt(this IServiceCollection serviceCollection, ReverseEngineerCommandOptions options, List errors, List warnings, List info) { - if (options == null) - { - throw new ArgumentNullException(nameof(options)); - } + ArgumentNullException.ThrowIfNull(options); - if (serviceCollection == null) - { - throw new ArgumentNullException(nameof(serviceCollection)); - } + ArgumentNullException.ThrowIfNull(serviceCollection); var reporter = new OperationReporter( new OperationReportHandler( diff --git a/src/GUI/RevEng.Core.60/TableListBuilder.cs b/src/GUI/RevEng.Core.60/TableListBuilder.cs index 88b57e0c8..e4ace13d1 100644 --- a/src/GUI/RevEng.Core.60/TableListBuilder.cs +++ b/src/GUI/RevEng.Core.60/TableListBuilder.cs @@ -26,10 +26,7 @@ public TableListBuilder( IDatabaseModelFactory databaseModelFactory, SchemaInfo[] schemas) { - if (options is null) - { - throw new ArgumentNullException(nameof(options)); - } + ArgumentNullException.ThrowIfNull(options); this.procedureModelFactory = procedureModelFactory; this.functionModelFactory = functionModelFactory; diff --git a/src/GUI/RevEng.Core.70/RevEng.Core.70.csproj b/src/GUI/RevEng.Core.70/RevEng.Core.70.csproj index 89b3decba..e8b86aefe 100644 --- a/src/GUI/RevEng.Core.70/RevEng.Core.70.csproj +++ b/src/GUI/RevEng.Core.70/RevEng.Core.70.csproj @@ -35,7 +35,7 @@ - + diff --git a/src/GUI/efpt60.core/EFCoreCompareBuilder.cs b/src/GUI/efpt60.core/EFCoreCompareBuilder.cs index 87519ea7e..67ebc0590 100644 --- a/src/GUI/efpt60.core/EFCoreCompareBuilder.cs +++ b/src/GUI/efpt60.core/EFCoreCompareBuilder.cs @@ -20,10 +20,7 @@ public static List> GenerateDbContextList(string outputPat public static List> GenerateSchemaCompareResult(string outputPath, string startupOutputPath, string connectionString, string dbContexts) { - if (dbContexts == null) - { - throw new ArgumentNullException(nameof(dbContexts)); - } + ArgumentNullException.ThrowIfNull(dbContexts); return GetCompareResult(outputPath, startupOutputPath ?? outputPath, connectionString, dbContexts); } diff --git a/src/GUI/efpt60.core/EFCoreMigrationsBuilder.cs b/src/GUI/efpt60.core/EFCoreMigrationsBuilder.cs index 9e0bc3712..22c79d946 100644 --- a/src/GUI/efpt60.core/EFCoreMigrationsBuilder.cs +++ b/src/GUI/efpt60.core/EFCoreMigrationsBuilder.cs @@ -123,14 +123,14 @@ private static string GetMigrationStatus(DbContext context) var migrations = context.Database.GetMigrations().ToArray(); - if (!migrations.Any()) + if (migrations.Length == 0) { return "NoMigrations"; } var pendingMigrations = context.Database.GetPendingMigrations().ToArray(); - if (pendingMigrations.Any()) + if (pendingMigrations.Length != 0) { return "Pending"; } diff --git a/src/GUI/efpt60.core/Program.cs b/src/GUI/efpt60.core/Program.cs index a04ae1eca..ef21da4e6 100644 --- a/src/GUI/efpt60.core/Program.cs +++ b/src/GUI/efpt60.core/Program.cs @@ -16,10 +16,7 @@ public static int Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; - if (args == null) - { - throw new ArgumentNullException(nameof(args)); - } + ArgumentNullException.ThrowIfNull(args); if (args.Length > 0) { diff --git a/src/GUI/efreveng60/Program.cs b/src/GUI/efreveng60/Program.cs index 43982a486..8dcde9fad 100644 --- a/src/GUI/efreveng60/Program.cs +++ b/src/GUI/efreveng60/Program.cs @@ -23,10 +23,7 @@ public static async System.Threading.Tasks.Task Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; - if (args == null) - { - throw new ArgumentNullException(nameof(args)); - } + ArgumentNullException.ThrowIfNull(args); if (args.Length > 0) {