Skip to content

Commit e6f2165

Browse files
committed
Package updates and code cleanup.
1 parent ec46bea commit e6f2165

File tree

14 files changed

+114
-115
lines changed

14 files changed

+114
-115
lines changed

SQLHelper.SpeedTests/SQLHelper.SpeedTests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<TargetFramework>netcoreapp3.0</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Serilog.Sinks.File" Version="4.0.0" />
9+
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
1010
<PackageReference Include="sundial.core" Version="2.0.3" />
1111
</ItemGroup>
1212

src/SQLHelper.DB/ExtensionMethods/DbCommandExtensions.cs

+20-20
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static DbCommand AddParameter(this DbCommand command, string id, string v
6161
Length = -1;
6262
}
6363

64-
DbParameter Parameter = command.GetOrCreateParameter(id);
64+
var Parameter = command.GetOrCreateParameter(id);
6565
Parameter.Value = string.IsNullOrEmpty(value) ? DBNull.Value : (object)value;
6666
Parameter.IsNullable = string.IsNullOrEmpty(value);
6767
Parameter.DbType = DbType.String;
@@ -81,7 +81,7 @@ public static DbCommand AddParameter(this DbCommand command, string id, string v
8181
/// <returns>The DbCommand object</returns>
8282
/// <exception cref="ArgumentNullException">command or id</exception>
8383
public static DbCommand AddParameter(this DbCommand command, string id, SqlDbType type,
84-
object value = null, ParameterDirection direction = ParameterDirection.Input)
84+
object? value = null, ParameterDirection direction = ParameterDirection.Input)
8585
{
8686
if (command == null)
8787
throw new ArgumentNullException(nameof(command));
@@ -100,16 +100,16 @@ public static DbCommand AddParameter(this DbCommand command, string id, SqlDbTyp
100100
/// <param name="direction">Direction that the parameter goes (in or out)</param>
101101
/// <returns>The DbCommand object</returns>
102102
/// <exception cref="ArgumentNullException">command or id</exception>
103-
public static DbCommand AddParameter<DataType>(this DbCommand command, string id, DataType value = default(DataType),
103+
public static DbCommand AddParameter<DataType>(this DbCommand command, string id, DataType value = default,
104104
ParameterDirection direction = ParameterDirection.Input)
105105
{
106106
if (command == null)
107107
throw new ArgumentNullException(nameof(command));
108108
if (string.IsNullOrEmpty(id))
109109
throw new ArgumentNullException(nameof(id));
110110
return command.AddParameter(id,
111-
new GenericEqualityComparer<DataType>().Equals(value, default(DataType)) ? typeof(DataType).To(DbType.Int32) : value.GetType().To(DbType.Int32),
112-
value, direction);
111+
new GenericEqualityComparer<DataType>().Equals(value, default!) ? typeof(DataType).To(DbType.Int32) : value?.GetType().To(DbType.Int32) ?? DbType.Int32,
112+
value!, direction);
113113
}
114114

115115
/// <summary>
@@ -122,17 +122,17 @@ public static DbCommand AddParameter(this DbCommand command, string id, SqlDbTyp
122122
/// <param name="direction">Direction that the parameter goes (in or out)</param>
123123
/// <returns>The DbCommand object</returns>
124124
/// <exception cref="ArgumentNullException">command or id</exception>
125-
public static DbCommand AddParameter(this DbCommand command, string id, DbType type, object value = null,
125+
public static DbCommand AddParameter(this DbCommand command, string id, DbType type, object? value = null,
126126
ParameterDirection direction = ParameterDirection.Input)
127127
{
128128
if (command == null)
129129
throw new ArgumentNullException(nameof(command));
130130
if (string.IsNullOrEmpty(id))
131131
throw new ArgumentNullException(nameof(id));
132-
DbParameter Parameter = command.GetOrCreateParameter(id);
132+
var Parameter = command.GetOrCreateParameter(id);
133133
Parameter.IsNullable = value == null || DBNull.Value == value;
134134
Parameter.Value = Parameter.IsNullable ? DBNull.Value : value;
135-
if (type != default(DbType) && !BadDbTypes.Contains(type))
135+
if (type != default && !BadDbTypes.Contains(type))
136136
Parameter.DbType = type;
137137
Parameter.Direction = direction;
138138
return command;
@@ -144,7 +144,7 @@ public static DbCommand AddParameter(this DbCommand command, string id, DbType t
144144
/// <param name="command">Command object</param>
145145
/// <param name="retries">The retries.</param>
146146
/// <returns>A transaction object</returns>
147-
public static DbTransaction BeginTransaction(this DbCommand command, int retries = 0)
147+
public static DbTransaction? BeginTransaction(this DbCommand command, int retries = 0)
148148
{
149149
if (command == null || command.Connection == null)
150150
return null;
@@ -158,7 +158,7 @@ public static DbTransaction BeginTransaction(this DbCommand command, int retries
158158
/// </summary>
159159
/// <param name="command">Command object</param>
160160
/// <returns>The DBCommand object</returns>
161-
public static DbCommand ClearParameters(this DbCommand command)
161+
public static DbCommand? ClearParameters(this DbCommand command)
162162
{
163163
command?.Parameters?.Clear();
164164
return command;
@@ -169,7 +169,7 @@ public static DbCommand ClearParameters(this DbCommand command)
169169
/// </summary>
170170
/// <param name="command">Command object</param>
171171
/// <returns>The DBCommand object</returns>
172-
public static DbCommand Close(this DbCommand command)
172+
public static DbCommand? Close(this DbCommand command)
173173
{
174174
if (command?.Connection != null
175175
&& command.Connection.State != ConnectionState.Closed)
@@ -185,7 +185,7 @@ public static DbCommand Close(this DbCommand command)
185185
/// </summary>
186186
/// <param name="command">Command object</param>
187187
/// <returns>The DBCommand object</returns>
188-
public static DbCommand Commit(this DbCommand command)
188+
public static DbCommand? Commit(this DbCommand command)
189189
{
190190
command?.Transaction?.Commit();
191191
return command;
@@ -199,7 +199,7 @@ public static DbCommand Commit(this DbCommand command)
199199
/// <param name="defaultValue">Default value if there is an issue</param>
200200
/// <param name="retries">The retries.</param>
201201
/// <returns>The object of the first row and first column</returns>
202-
public static DataType ExecuteScalar<DataType>(this DbCommand command, DataType defaultValue = default(DataType), int retries = 0)
202+
public static DataType ExecuteScalar<DataType>(this DbCommand command, DataType defaultValue = default, int retries = 0)
203203
{
204204
if (command == null)
205205
return defaultValue;
@@ -215,7 +215,7 @@ public static DbCommand Commit(this DbCommand command)
215215
/// <param name="defaultValue">Default value if there is an issue</param>
216216
/// <param name="retries">The retries.</param>
217217
/// <returns>The object of the first row and first column</returns>
218-
public static async Task<DataType> ExecuteScalarAsync<DataType>(this DbCommand command, DataType defaultValue = default(DataType), int retries = 0)
218+
public static async Task<DataType> ExecuteScalarAsync<DataType>(this DbCommand command, DataType defaultValue = default, int retries = 0)
219219
{
220220
if (command == null)
221221
return defaultValue;
@@ -236,7 +236,7 @@ public static DbParameter GetOrCreateParameter(this DbCommand command, string id
236236
{
237237
return command.Parameters[id];
238238
}
239-
DbParameter Parameter = command.CreateParameter();
239+
var Parameter = command.CreateParameter();
240240
Parameter.ParameterName = id;
241241
command.Parameters.Add(Parameter);
242242
return Parameter;
@@ -253,7 +253,7 @@ public static DbParameter GetOrCreateParameter(this DbCommand command, string id
253253
/// if the parameter exists (and isn't null or empty), it returns the parameter's value.
254254
/// Otherwise the default value is returned.
255255
/// </returns>
256-
public static DataType GetOutputParameter<DataType>(this DbCommand command, string id, DataType defaultValue = default(DataType))
256+
public static DataType GetOutputParameter<DataType>(this DbCommand command, string id, DataType defaultValue = default)
257257
{
258258
return command?.Parameters[id] != null ?
259259
command.Parameters[id].Value.To(defaultValue) :
@@ -266,9 +266,9 @@ public static DbParameter GetOrCreateParameter(this DbCommand command, string id
266266
/// <param name="command">Command object</param>
267267
/// <param name="retries">The retries.</param>
268268
/// <returns>The DBCommand object</returns>
269-
public static DbCommand Open(this DbCommand command, int retries = 0)
269+
public static DbCommand? Open(this DbCommand command, int retries = 0)
270270
{
271-
Exception holder = null;
271+
Exception? holder = null;
272272
while (retries >= 0)
273273
{
274274
try
@@ -287,15 +287,15 @@ public static DbCommand Open(this DbCommand command, int retries = 0)
287287
}
288288
--retries;
289289
}
290-
throw holder;
290+
throw holder!;
291291
}
292292

293293
/// <summary>
294294
/// Rolls back a transaction
295295
/// </summary>
296296
/// <param name="command">Command object</param>
297297
/// <returns>The DBCommand object</returns>
298-
public static DbCommand Rollback(this DbCommand command)
298+
public static DbCommand? Rollback(this DbCommand command)
299299
{
300300
command?.Transaction?.Rollback();
301301
return command;

src/SQLHelper.DB/ExtensionMethods/IDataRecordExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static class IDataRecordExtensions
3636
/// if the parameter exists (and isn't null or empty), it returns the parameter's value.
3737
/// Otherwise the default value is returned.
3838
/// </returns>
39-
public static DataType GetParameter<DataType>(this IDataRecord reader, string id, DataType defaultValue = default(DataType))
39+
public static DataType GetParameter<DataType>(this IDataRecord reader, string id, DataType defaultValue = default)
4040
{
4141
if (reader == null)
4242
return defaultValue;
@@ -59,7 +59,7 @@ public static class IDataRecordExtensions
5959
/// if the parameter exists (and isn't null or empty), it returns the parameter's value.
6060
/// Otherwise the default value is returned.
6161
/// </returns>
62-
public static DataType GetParameter<DataType>(this IDataRecord reader, int position, DataType defaultValue = default(DataType))
62+
public static DataType GetParameter<DataType>(this IDataRecord reader, int position, DataType defaultValue = default)
6363
{
6464
if (reader == null)
6565
return defaultValue;
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// This file is used by Code Analysis to maintain SuppressMessage attributes that are applied to
2+
// this project. Project-level suppressions either have no target or are given a specific target and
3+
// scoped to a namespace, type, member, etc.
4+
5+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "SecurityIntelliSenseCS:MS Security rules violation", Justification = "<Pending>", Scope = "member", Target = "~M:SQLHelperDB.HelperClasses.Batch.SetupCommand(System.Data.Common.DbConnection,System.Data.Common.DbCommand)")]
6+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "SecurityIntelliSenseCS:MS Security rules violation", Justification = "<Pending>", Scope = "member", Target = "~M:SQLHelperDB.HelperClasses.Batch.SetupParameters(System.Int32@,System.Collections.Generic.List{SQLHelperDB.HelperClasses.Interfaces.IParameter},System.Boolean@,System.String@,System.Int32@)")]
7+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "<Pending>", Scope = "member", Target = "~M:SQLHelperDB.HelperClasses.Batch.GetResults(System.Collections.Generic.List{System.Collections.Generic.List{}},System.Data.Common.DbCommand,System.Collections.Generic.List{SQLHelperDB.HelperClasses.Interfaces.IParameter},System.Boolean,System.String)")]
8+
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "<Pending>", Scope = "member", Target = "~M:SQLHelperDB.HelperClasses.Batch.GetResultsAsync(System.Collections.Generic.List{System.Collections.Generic.List{}},System.Data.Common.DbCommand,System.Collections.Generic.List{SQLHelperDB.HelperClasses.Interfaces.IParameter},System.Boolean,System.String)~System.Threading.Tasks.Task")]

src/SQLHelper.DB/HelperClasses/BaseClasses/ParameterBase.cs

+7-8
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected ParameterBase(string id, DataType value, ParameterDirection direction
5555
/// What the database expects as the parameter starting string ("@" for SQL Server, ":" for
5656
/// Oracle, etc.)
5757
/// </param>
58-
protected ParameterBase(string id, SqlDbType type, object value = null, ParameterDirection direction = ParameterDirection.Input, string parameterStarter = "@")
58+
protected ParameterBase(string id, SqlDbType type, object? value = null, ParameterDirection direction = ParameterDirection.Input, string parameterStarter = "@")
5959
: this(id, type.To(DbType.Int32), value, direction, parameterStarter)
6060
{
6161
}
@@ -71,10 +71,10 @@ protected ParameterBase(string id, SqlDbType type, object value = null, Paramete
7171
/// What the database expects as the parameter starting string ("@" for SQL Server, ":" for
7272
/// Oracle, etc.)
7373
/// </param>
74-
protected ParameterBase(string id, DbType type, object value = null, ParameterDirection direction = ParameterDirection.Input, string parameterStarter = "@")
74+
protected ParameterBase(string id, DbType type, object? value = null, ParameterDirection direction = ParameterDirection.Input, string parameterStarter = "@")
7575
{
7676
ID = id;
77-
Value = (DataType)value;
77+
Value = (DataType)value!;
7878
DatabaseType = type;
7979
Direction = direction;
8080
BatchID = id;
@@ -100,7 +100,7 @@ protected ParameterBase(string id, DbType type, object value = null, ParameterDi
100100
/// Gets the internal value.
101101
/// </summary>
102102
/// <value>The internal value.</value>
103-
public object InternalValue { get { return Value; } }
103+
public object InternalValue { get { return Value!; } }
104104

105105
/// <summary>
106106
/// Starting string of the parameter
@@ -178,8 +178,7 @@ public string AddParameter(string command)
178178
/// <returns>True if they are equal, false otherwise</returns>
179179
public override bool Equals(object obj)
180180
{
181-
var OtherParameter = obj as ParameterBase<DataType>;
182-
return OtherParameter != null
181+
return (obj is ParameterBase<DataType> OtherParameter)
183182
&& OtherParameter.DatabaseType == DatabaseType
184183
&& OtherParameter.Direction == Direction
185184
&& OtherParameter.ID == ID
@@ -190,8 +189,8 @@ public override bool Equals(object obj)
190189
/// Returns a hash code for this instance.
191190
/// </summary>
192191
/// <returns>
193-
/// A hash code for this instance, suitable for use in hashing algorithms and data structures
194-
/// like a hash table.
192+
/// A hash code for this instance, suitable for use in hashing algorithms and data
193+
/// structures like a hash table.
195194
/// </returns>
196195
public override int GetHashCode()
197196
{

0 commit comments

Comments
 (0)