Skip to content

Commit 488ef5b

Browse files
committed
Use target-typed new.
1 parent 739416c commit 488ef5b

25 files changed

+221
-221
lines changed

src/MySqlConnector/Authentication/AuthenticationPlugins.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ internal static bool TryGetPlugin(string name, [NotNullWhen(true)] out IAuthenti
3030
return s_plugins.TryGetValue(name, out plugin);
3131
}
3232

33-
static readonly object s_lock = new object();
34-
static readonly Dictionary<string, IAuthenticationPlugin> s_plugins = new Dictionary<string, IAuthenticationPlugin>();
33+
static readonly object s_lock = new();
34+
static readonly Dictionary<string, IAuthenticationPlugin> s_plugins = new();
3535
}
3636
}

src/MySqlConnector/Core/CachedProcedure.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ FROM information_schema.parameters
8787
while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false))
8888
{
8989
var dataType = ParseDataType(reader.GetString(3), out var unsigned, out var length);
90-
parameters.Add(new CachedParameter(
90+
parameters.Add(new(
9191
reader.GetInt32(0),
9292
!reader.IsDBNull(1) ? reader.GetString(1) : null,
9393
!reader.IsDBNull(2) ? reader.GetString(2) : "",

src/MySqlConnector/Core/ConnectionPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ static ConnectionPool()
539539
#endif
540540

541541
static readonly IMySqlConnectorLogger Log = MySqlConnectorLogManager.CreateLogger(nameof(ConnectionPool));
542-
static readonly ConcurrentDictionary<string, ConnectionPool?> s_pools = new ConcurrentDictionary<string, ConnectionPool?>();
542+
static readonly ConcurrentDictionary<string, ConnectionPool?> s_pools = new();
543543

544544
static int s_poolId;
545545
static ConnectionStringPool? s_mruCache;

src/MySqlConnector/Core/NormalizedSchema.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal sealed class NormalizedSchema
99
private const string ReUnQuoted = @"([^\.`]+)";
1010
private static readonly string ReEither = $@"(?:{ReQuoted}|{ReUnQuoted})";
1111

12-
private static readonly Regex NameRe = new Regex(
12+
private static readonly Regex NameRe = new(
1313
$@"^\s*{ReEither}\s*(?:\.\s*{ReEither}\s*)?$",
1414
RegexOptions.Compiled);
1515

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public async Task PrepareAsync(IMySqlCommand command, IOBehavior ioBehavior, Can
192192
var payloadLength = payload.Span.Length;
193193
Utility.Resize(ref columnsAndParameters, columnsAndParametersSize + payloadLength);
194194
payload.Span.CopyTo(columnsAndParameters.Array.AsSpan().Slice(columnsAndParametersSize));
195-
parameters[i] = ColumnDefinitionPayload.Create(new ResizableArraySegment<byte>(columnsAndParameters, columnsAndParametersSize, payloadLength));
195+
parameters[i] = ColumnDefinitionPayload.Create(new(columnsAndParameters, columnsAndParametersSize, payloadLength));
196196
columnsAndParametersSize += payloadLength;
197197
}
198198
if (!SupportsDeprecateEof)
@@ -212,7 +212,7 @@ public async Task PrepareAsync(IMySqlCommand command, IOBehavior ioBehavior, Can
212212
var payloadLength = payload.Span.Length;
213213
Utility.Resize(ref columnsAndParameters, columnsAndParametersSize + payloadLength);
214214
payload.Span.CopyTo(columnsAndParameters.Array.AsSpan().Slice(columnsAndParametersSize));
215-
columns[i] = ColumnDefinitionPayload.Create(new ResizableArraySegment<byte>(columnsAndParameters, columnsAndParametersSize, payloadLength));
215+
columns[i] = ColumnDefinitionPayload.Create(new(columnsAndParameters, columnsAndParametersSize, payloadLength));
216216
columnsAndParametersSize += payloadLength;
217217
}
218218
if (!SupportsDeprecateEof)
@@ -222,11 +222,11 @@ public async Task PrepareAsync(IMySqlCommand command, IOBehavior ioBehavior, Can
222222
}
223223
}
224224

225-
preparedStatements.Add(new PreparedStatement(response.StatementId, statement, columns, parameters));
225+
preparedStatements.Add(new(response.StatementId, statement, columns, parameters));
226226
}
227227

228228
m_preparedStatements ??= new Dictionary<string, PreparedStatements>();
229-
m_preparedStatements.Add(commandText, new PreparedStatements(preparedStatements, parsedStatements));
229+
m_preparedStatements.Add(commandText, new(preparedStatements, parsedStatements));
230230
}
231231

232232
public PreparedStatements? TryGetPreparedStatement(string commandText)

src/MySqlConnector/Core/TypeMapper.cs

Lines changed: 70 additions & 70 deletions
Large diffs are not rendered by default.

src/MySqlConnector/MySql.Data.MySqlClient/MySqlBulkCopy.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private async ValueTask WriteToServerAsync(IOBehavior ioBehavior, CancellationTo
182182
else if (addDefaultMappings)
183183
{
184184
Log.Debug("Adding default column mapping from SourceOrdinal {0} to DestinationColumn {1}", i, destinationColumn);
185-
columnMappings.Add(new MySqlBulkCopyColumnMapping(i, destinationColumn));
185+
columnMappings.Add(new(i, destinationColumn));
186186
}
187187
}
188188
}
@@ -249,13 +249,13 @@ static void AddColumnMapping(List<MySqlBulkCopyColumnMapping> columnMappings, bo
249249
{
250250
Log.Debug("Setting expression to map SourceOrdinal {0} to DestinationColumn {1}", columnMapping.SourceOrdinal, destinationColumn);
251251
columnMappings.Remove(columnMapping);
252-
columnMappings.Add(new MySqlBulkCopyColumnMapping(columnMapping.SourceOrdinal, variableName, expression));
252+
columnMappings.Add(new(columnMapping.SourceOrdinal, variableName, expression));
253253
}
254254
}
255255
else if (addDefaultMappings)
256256
{
257257
Log.Debug("Adding default column mapping from SourceOrdinal {0} to DestinationColumn {1}", destinationOrdinal, destinationColumn);
258-
columnMappings.Add(new MySqlBulkCopyColumnMapping(destinationOrdinal, variableName, expression));
258+
columnMappings.Add(new(destinationOrdinal, variableName, expression));
259259
}
260260
}
261261
}

src/MySqlConnector/MySql.Data.MySqlClient/MySqlBulkLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ internal static bool TryGetAndRemoveSource(string sourceKey, [NotNullWhen(true)]
221221

222222
private static string GenerateSourceFileName() => SourcePrefix + Guid.NewGuid().ToString("N");
223223

224-
static readonly object s_lock = new object();
225-
static readonly Dictionary<string, object> s_sources = new Dictionary<string, object>();
224+
static readonly object s_lock = new();
225+
static readonly Dictionary<string, object> s_sources = new();
226226
}
227227
}

src/MySqlConnector/MySql.Data.MySqlClient/MySqlClientFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace MySql.Data.MySqlClient
44
{
55
public sealed class MySqlClientFactory : DbProviderFactory
66
{
7-
public static readonly MySqlClientFactory Instance = new MySqlClientFactory();
7+
public static readonly MySqlClientFactory Instance = new();
88

99
public override DbCommand CreateCommand() => new MySqlCommand();
1010
public override DbConnection CreateConnection() => new MySqlConnection();

src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ internal void FinishQuerying(bool hasWarnings)
698698
using (var reader = command.ExecuteReader())
699699
{
700700
while (reader.Read())
701-
errors.Add(new MySqlError(reader.GetString(0), reader.GetInt32(1), reader.GetString(2)));
701+
errors.Add(new(reader.GetString(0), reader.GetInt32(1), reader.GetString(2)));
702702
}
703703

704704
InfoMessage(this, new MySqlInfoMessageEventArgs(errors.ToArray()));
@@ -920,12 +920,12 @@ private ConnectionSettings GetConnectionSettings() =>
920920
private ConnectionSettings GetInitializedConnectionSettings() => m_connectionSettings!;
921921

922922
static readonly IMySqlConnectorLogger Log = MySqlConnectorLogManager.CreateLogger(nameof(MySqlConnection));
923-
static readonly StateChangeEventArgs s_stateChangeClosedConnecting = new StateChangeEventArgs(ConnectionState.Closed, ConnectionState.Connecting);
924-
static readonly StateChangeEventArgs s_stateChangeConnectingOpen = new StateChangeEventArgs(ConnectionState.Connecting, ConnectionState.Open);
925-
static readonly StateChangeEventArgs s_stateChangeOpenClosed = new StateChangeEventArgs(ConnectionState.Open, ConnectionState.Closed);
923+
static readonly StateChangeEventArgs s_stateChangeClosedConnecting = new(ConnectionState.Closed, ConnectionState.Connecting);
924+
static readonly StateChangeEventArgs s_stateChangeConnectingOpen = new(ConnectionState.Connecting, ConnectionState.Open);
925+
static readonly StateChangeEventArgs s_stateChangeOpenClosed = new(ConnectionState.Open, ConnectionState.Closed);
926926
#if !NETSTANDARD1_3
927-
static readonly object s_lock = new object();
928-
static readonly Dictionary<System.Transactions.Transaction, List<EnlistedTransactionBase>> s_transactionConnections = new Dictionary<System.Transactions.Transaction, List<EnlistedTransactionBase>>();
927+
static readonly object s_lock = new();
928+
static readonly Dictionary<System.Transactions.Transaction, List<EnlistedTransactionBase>> s_transactionConnections = new();
929929
#endif
930930

931931
string m_connectionString;

0 commit comments

Comments
 (0)