Skip to content

Commit 21f5da3

Browse files
committed
Use out variables.
1 parent 403cad7 commit 21f5da3

File tree

7 files changed

+15
-32
lines changed

7 files changed

+15
-32
lines changed

src/MySqlConnector/MySqlClient/ConnectionPool.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ public async Task<MySqlSession> GetSessionAsync(IOBehavior ioBehavior, Cancellat
2222

2323
try
2424
{
25-
MySqlSession session;
2625
// check for a pooled session
27-
if (m_sessions.TryDequeue(out session))
26+
if (m_sessions.TryDequeue(out var session))
2827
{
2928
if (session.PoolGeneration != m_generation || !await session.TryPingAsync(ioBehavior, cancellationToken).ConfigureAwait(false))
3029
{
@@ -91,8 +90,7 @@ public async Task ClearAsync(IOBehavior ioBehavior, CancellationToken cancellati
9190

9291
try
9392
{
94-
MySqlSession session;
95-
if (m_sessions.TryDequeue(out session))
93+
if (m_sessions.TryDequeue(out var session))
9694
{
9795
if (session.PoolGeneration != m_generation)
9896
{
@@ -122,8 +120,7 @@ public static ConnectionPool GetPool(ConnectionSettings cs)
122120

123121
var key = cs.ConnectionString;
124122

125-
ConnectionPool pool;
126-
if (!s_pools.TryGetValue(key, out pool))
123+
if (!s_pools.TryGetValue(key, out var pool))
127124
{
128125
pool = s_pools.GetOrAdd(cs.ConnectionString, newKey => new ConnectionPool(cs));
129126
}

src/MySqlConnector/MySqlClient/MySqlConnection.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,7 @@ internal async Task<CachedProcedure> GetCachedProcedure(IOBehavior ioBehavior, s
228228
m_cachedProcedures = new Dictionary<string, CachedProcedure>();
229229

230230
var normalized = NormalizedSchema.MustNormalize(name, Database);
231-
CachedProcedure cachedProcedure;
232-
if (!m_cachedProcedures.TryGetValue(normalized.FullyQualified, out cachedProcedure))
231+
if (!m_cachedProcedures.TryGetValue(normalized.FullyQualified, out var cachedProcedure))
233232
{
234233
cachedProcedure = await CachedProcedure.FillAsync(ioBehavior, this, normalized.Schema, normalized.Component, cancellationToken).ConfigureAwait(false);
235234
m_cachedProcedures[normalized.FullyQualified] = cachedProcedure;

src/MySqlConnector/MySqlClient/MySqlConnectionStringBuilder.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,8 @@ internal abstract class MySqlConnectionStringOption
241241
public static readonly MySqlConnectionStringOption<bool> UseAffectedRows;
242242
public static readonly MySqlConnectionStringOption<bool> UseCompression;
243243

244-
public static MySqlConnectionStringOption TryGetOptionForKey(string key)
245-
{
246-
MySqlConnectionStringOption option;
247-
return s_options.TryGetValue(key, out option) ? option : null;
248-
}
244+
public static MySqlConnectionStringOption TryGetOptionForKey(string key) =>
245+
s_options.TryGetValue(key, out var option) ? option : null;
249246

250247
public static MySqlConnectionStringOption GetOptionForKey(string key)
251248
{
@@ -390,11 +387,8 @@ public MySqlConnectionStringOption(IReadOnlyList<string> keys, T defaultValue, F
390387
m_coerce = coerce;
391388
}
392389

393-
public T GetValue(MySqlConnectionStringBuilder builder)
394-
{
395-
object objectValue;
396-
return builder.TryGetValue(Key, out objectValue) ? ChangeType(objectValue) : m_defaultValue;
397-
}
390+
public T GetValue(MySqlConnectionStringBuilder builder) =>
391+
builder.TryGetValue(Key, out var objectValue) ? ChangeType(objectValue) : m_defaultValue;
398392

399393
public void SetValue(MySqlConnectionStringBuilder builder, T value)
400394
{

src/MySqlConnector/MySqlClient/MySqlParameterCollection.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,7 @@ internal int NormalizedIndexOf(string parameterName)
110110
{
111111
if (parameterName == null)
112112
throw new ArgumentNullException(nameof(parameterName));
113-
int index;
114-
return m_nameToIndex.TryGetValue(MySqlParameter.NormalizeParameterName(parameterName), out index) ? index : -1;
113+
return m_nameToIndex.TryGetValue(MySqlParameter.NormalizeParameterName(parameterName), out var index) ? index : -1;
115114
}
116115

117116
public override void Insert(int index, object value)
@@ -184,8 +183,7 @@ internal int FlexibleIndexOf(string parameterName)
184183
{
185184
if (parameterName == null)
186185
throw new ArgumentNullException(nameof(parameterName));
187-
int index;
188-
return m_nameToIndex.TryGetValue(MySqlParameter.NormalizeParameterName(parameterName), out index) ? index : -1;
186+
return m_nameToIndex.TryGetValue(MySqlParameter.NormalizeParameterName(parameterName), out var index) ? index : -1;
189187
}
190188

191189
private void AddParameter(MySqlParameter parameter)

src/MySqlConnector/MySqlClient/Results/Row.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ public Guid GetGuid(int ordinal)
139139
if (value is Guid)
140140
return (Guid) value;
141141

142-
Guid guid;
143-
if (Guid.TryParse(value as string, out guid))
142+
if (Guid.TryParse(value as string, out var guid))
144143
return guid;
145144

146145
byte[] bytes = value as byte[];

src/MySqlConnector/MySqlClient/Types/TypeMapper.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,13 @@ private void AddColumnTypeMapping(ColumnTypeMapping columnTypeMapping)
109109

110110
internal DbTypeMapping GetDbTypeMapping(Type clrType)
111111
{
112-
DbTypeMapping dbTypeMapping;
113-
m_dbTypeMappingsByClrType.TryGetValue(clrType, out dbTypeMapping);
112+
m_dbTypeMappingsByClrType.TryGetValue(clrType, out var dbTypeMapping);
114113
return dbTypeMapping;
115114
}
116115

117116
internal DbTypeMapping GetDbTypeMapping(DbType dbType)
118117
{
119-
DbTypeMapping dbTypeMapping;
120-
m_dbTypeMappingsByDbType.TryGetValue(dbType, out dbTypeMapping);
118+
m_dbTypeMappingsByDbType.TryGetValue(dbType, out var dbTypeMapping);
121119
return dbTypeMapping;
122120
}
123121

@@ -128,8 +126,7 @@ internal DbTypeMapping GetDbTypeMapping(string columnTypeName, bool unsigned=fal
128126

129127
internal ColumnTypeMapping GetColumnTypeMapping(string columnTypeName, bool unsigned=false, int length=0)
130128
{
131-
ColumnTypeMapping columnTypeMapping;
132-
if (!m_columnTypeMappingLookup.TryGetValue(ColumnTypeMapping.CreateLookupKey(columnTypeName, unsigned, length), out columnTypeMapping) && length != 0)
129+
if (!m_columnTypeMappingLookup.TryGetValue(ColumnTypeMapping.CreateLookupKey(columnTypeName, unsigned, length), out var columnTypeMapping) && length != 0)
133130
m_columnTypeMappingLookup.TryGetValue(ColumnTypeMapping.CreateLookupKey(columnTypeName, unsigned, 0), out columnTypeMapping);
134131
return columnTypeMapping;
135132
}

src/MySqlConnector/Protocol/Serialization/CompressedPayloadHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ public ValueTask<int> WritePayloadAsync(ArraySegment<byte> payload, IOBehavior i
4141
if (m_uncompressedStream.Length == 0)
4242
return default(ValueTask<int>);
4343

44-
ArraySegment<byte> uncompressedData;
45-
if (!m_uncompressedStream.TryGetBuffer(out uncompressedData))
44+
if (!m_uncompressedStream.TryGetBuffer(out var uncompressedData))
4645
throw new InvalidOperationException("Couldn't get uncompressed stream buffer.");
4746

4847
return CompressAndWrite(uncompressedData, ioBehavior)

0 commit comments

Comments
 (0)