Skip to content

Commit 4fb1ea2

Browse files
Replace empty array with Array.Empty<T>, add compound assignment, fix of grammar typo (#1459)
Misc cleanup
1 parent 2bc267f commit 4fb1ea2

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

Dapper.Rainbow/Database.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ internal void InitDatabase(DbConnection connection, int commandTimeout)
199199
{
200200
_connection = connection;
201201
_commandTimeout = commandTimeout;
202-
tableConstructor = tableConstructor ?? CreateTableConstructorForTable();
202+
tableConstructor ??= CreateTableConstructorForTable();
203203

204204
tableConstructor(this as TDatabase);
205205
}
@@ -320,7 +320,7 @@ private bool TableExists(string name)
320320
name = name.Replace("[", "");
321321
name = name.Replace("]", "");
322322

323-
if (name.Contains("."))
323+
if (name.IndexOf('.') > 0)
324324
{
325325
var parts = name.Split('.');
326326
if (parts.Length == 2)

Dapper.Tests/ParameterTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ public void PassInIntArray()
197197
public void PassInEmptyIntArray()
198198
{
199199
Assert.Equal(
200-
new int[0],
201-
connection.Query<int>("select * from (select 1 as Id union all select 2 union all select 3) as X where Id in @Ids", new { Ids = new int[0] })
200+
Array.Empty<int>(),
201+
connection.Query<int>("select * from (select 1 as Id union all select 2 union all select 3) as X where Id in @Ids", new { Ids = Array.Empty<int>() })
202202
);
203203
}
204204

Dapper/CustomPropertyTypeMap.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public CustomPropertyTypeMap(Type type, Func<Type, string, PropertyInfo> propert
2929
/// <param name="types">DataReader column types</param>
3030
/// <returns>Default constructor</returns>
3131
public ConstructorInfo FindConstructor(string[] names, Type[] types) =>
32-
_type.GetConstructor(new Type[0]);
32+
_type.GetConstructor(Array.Empty<Type>());
3333

3434
/// <summary>
3535
/// Always returns null

Dapper/DynamicParameters.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void AddDynamicParams(object param)
5555
var dictionary = obj as IEnumerable<KeyValuePair<string, object>>;
5656
if (dictionary == null)
5757
{
58-
templates = templates ?? new List<object>();
58+
templates ??= new List<object>();
5959
templates.Add(obj);
6060
}
6161
else
@@ -78,7 +78,7 @@ public void AddDynamicParams(object param)
7878

7979
if (subDynamic.templates != null)
8080
{
81-
templates = templates ?? new List<object>();
81+
templates ??= new List<object>();
8282
foreach (var t in subDynamic.templates)
8383
{
8484
templates.Add(t);
@@ -450,7 +450,7 @@ public DynamicParameters Output<T>(T target, Expression<Func<T, object>> express
450450

451451
// Queue the preparation to be fired off when adding parameters to the DbCommand
452452
MAKECALLBACK:
453-
(outputCallbacks ?? (outputCallbacks = new List<Action>())).Add(() =>
453+
(outputCallbacks ??= new List<Action>()).Add(() =>
454454
{
455455
// Finally, prep the parameter and attach the callback to it
456456
var targetMemberType = lastMemberAccess?.Type;

Dapper/SqlMapper.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,7 +1132,7 @@ internal enum Row
11321132
SingleOrDefault = 3
11331133
}
11341134

1135-
private static readonly int[] ErrTwoRows = new int[2], ErrZeroRows = new int[0];
1135+
private static readonly int[] ErrTwoRows = new int[2], ErrZeroRows = Array.Empty<int>();
11361136
private static void ThrowMultipleRows(Row row)
11371137
{
11381138
switch (row)
@@ -1214,7 +1214,7 @@ private static T QueryRowImpl<T>(IDbConnection cnn, Row row, ref CommandDefiniti
12141214
}
12151215

12161216
/// <summary>
1217-
/// Shared value deserilization path for QueryRowImpl and QueryRowAsync
1217+
/// Shared value deserialization path for QueryRowImpl and QueryRowAsync
12181218
/// </summary>
12191219
[MethodImpl(MethodImplOptions.AggressiveInlining)]
12201220
private static T ReadRow<T>(CacheInfo info, Identity identity, ref CommandDefinition command, Type effectiveType, IDataReader reader)
@@ -1429,7 +1429,7 @@ private static IEnumerable<TReturn> MultiMap<TFirst, TSecond, TThird, TFourth, T
14291429
private static IEnumerable<TReturn> MultiMapImpl<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh, TReturn>(this IDbConnection cnn, CommandDefinition command, Delegate map, string splitOn, IDataReader reader, Identity identity, bool finalize)
14301430
{
14311431
object param = command.Parameters;
1432-
identity = identity ?? new Identity<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(command.CommandText, command.CommandType, cnn, typeof(TFirst), param?.GetType());
1432+
identity ??= new Identity<TFirst, TSecond, TThird, TFourth, TFifth, TSixth, TSeventh>(command.CommandText, command.CommandType, cnn, typeof(TFirst), param?.GetType());
14331433
CacheInfo cinfo = GetCacheInfo(identity, param, command.AddToCache);
14341434

14351435
IDbCommand ownedCommand = null;
@@ -1499,7 +1499,7 @@ private static IEnumerable<TReturn> MultiMapImpl<TReturn>(this IDbConnection cnn
14991499
}
15001500

15011501
object param = command.Parameters;
1502-
identity = identity ?? new IdentityWithTypes(command.CommandText, command.CommandType, cnn, types[0], param?.GetType(), types);
1502+
identity ??= new IdentityWithTypes(command.CommandText, command.CommandType, cnn, types[0], param?.GetType(), types);
15031503
CacheInfo cinfo = GetCacheInfo(identity, param, command.AddToCache);
15041504

15051505
IDbCommand ownedCommand = null;
@@ -2386,8 +2386,8 @@ internal static IList<LiteralToken> GetLiteralTokens(string sql)
23862386
public static Action<IDbCommand, object> CreateParamInfoGenerator(Identity identity, bool checkForDuplicates, bool removeUnused) =>
23872387
CreateParamInfoGenerator(identity, checkForDuplicates, removeUnused, GetLiteralTokens(identity.sql));
23882388

2389-
private static bool IsValueTuple(Type type) => (type?.IsValueType == true
2390-
&& type.FullName.StartsWith("System.ValueTuple`", StringComparison.Ordinal))
2389+
private static bool IsValueTuple(Type type) => (type?.IsValueType == true
2390+
&& type.FullName.StartsWith("System.ValueTuple`", StringComparison.Ordinal))
23912391
|| (type != null && IsValueTuple(Nullable.GetUnderlyingType(type)));
23922392

23932393
internal static Action<IDbCommand, object> CreateParamInfoGenerator(Identity identity, bool checkForDuplicates, bool removeUnused, IList<LiteralToken> literals)
@@ -2410,7 +2410,7 @@ internal static Action<IDbCommand, object> CreateParamInfoGenerator(Identity ide
24102410

24112411
bool isStruct = type.IsValueType;
24122412
var _sizeLocal = (LocalBuilder)null;
2413-
LocalBuilder GetSizeLocal() => _sizeLocal ?? (_sizeLocal = il.DeclareLocal(typeof(int)));
2413+
LocalBuilder GetSizeLocal() => _sizeLocal ??= il.DeclareLocal(typeof(int));
24142414
il.Emit(OpCodes.Ldarg_1); // stack is now [untyped-param]
24152415

24162416
LocalBuilder typedParameterLocal;
@@ -3055,7 +3055,7 @@ public static Func<IDataReader, object> GetTypeDeserializer(
30553055
private static LocalBuilder GetTempLocal(ILGenerator il, ref Dictionary<Type, LocalBuilder> locals, Type type, bool initAndLoad)
30563056
{
30573057
if (type == null) throw new ArgumentNullException(nameof(type));
3058-
locals = locals ?? new Dictionary<Type, LocalBuilder>();
3058+
locals ??= new Dictionary<Type, LocalBuilder>();
30593059
if (!locals.TryGetValue(type, out LocalBuilder found))
30603060
{
30613061
found = il.DeclareLocal(type);
@@ -3193,7 +3193,7 @@ private static void GenerateValueTupleDeserializer(Type valueTupleType, IDataRea
31933193
if (nullableUnderlyingType != null)
31943194
{
31953195
var nullableTupleConstructor = valueTupleType.GetConstructor(new[] { nullableUnderlyingType });
3196-
3196+
31973197
il.Emit(OpCodes.Newobj, nullableTupleConstructor);
31983198
}
31993199

@@ -3777,7 +3777,7 @@ private static string __ToStringRecycle(this StringBuilder obj)
37773777
{
37783778
if (obj == null) return "";
37793779
var s = obj.ToString();
3780-
perThreadStringBuilderCache = perThreadStringBuilderCache ?? obj;
3780+
perThreadStringBuilderCache ??= obj;
37813781
return s;
37823782
}
37833783
}

0 commit comments

Comments
 (0)