Skip to content

Commit 3e2f7ea

Browse files
authored
avoid redundant exception type checks (dotnet#4100)
1 parent 3ae3274 commit 3e2f7ea

3 files changed

Lines changed: 16 additions & 14 deletions

File tree

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ManagedSni/SniTcpHandle.netcore.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,10 @@ public SniTcpHandle(
221221
{
222222
throw;
223223
}
224-
if (exRetry is SocketException || exRetry is ArgumentNullException
225-
|| exRetry is ArgumentException || exRetry is ArgumentOutOfRangeException || exRetry is AggregateException)
224+
if (exRetry is
225+
SocketException or
226+
ArgumentException or
227+
AggregateException)
226228
{
227229
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SniTcpHandle), EventType.INFO, "Connection Id {0}, Retrying exception {1}", args0: _connectionId, args1: exRetry?.Message);
228230
if (parallel)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationProviderManager.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,17 @@ static SqlAuthenticationProviderManager()
188188
// simply have no default and the app must provide one if they
189189
// attempt to use Active Directory authentication.
190190
catch (Exception ex)
191-
when (ex is ArgumentNullException ||
192-
ex is ArgumentException ||
193-
ex is BadImageFormatException ||
194-
ex is FileLoadException ||
195-
ex is FileNotFoundException ||
196-
ex is MemberAccessException ||
197-
ex is MethodAccessException ||
198-
ex is MissingMethodException ||
199-
ex is NotSupportedException ||
200-
ex is TargetInvocationException ||
201-
ex is TypeLoadException)
191+
when (ex is
192+
ArgumentException or
193+
BadImageFormatException or
194+
FileLoadException or
195+
FileNotFoundException or
196+
MemberAccessException or
197+
MethodAccessException or
198+
MissingMethodException or
199+
NotSupportedException or
200+
TargetInvocationException or
201+
TypeLoadException)
202202
{
203203
SqlClientEventSource.Log.TryTraceEvent(
204204
nameof(SqlAuthenticationProviderManager) +

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlQueryMetadataCache.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ internal bool GetQueryMetadataIfExists(SqlCommand sqlCommand)
129129
InvalidateCacheEntry(sqlCommand);
130130

131131
// If we get one of the expected exceptions, just fail the cache lookup, otherwise throw.
132-
if (ex is SqlException || ex is ArgumentException || ex is ArgumentNullException)
132+
if (ex is SqlException or ArgumentException)
133133
{
134134
foreach (SqlParameter paramToCleanup in sqlCommand.Parameters)
135135
{

0 commit comments

Comments
 (0)