Skip to content

Commit

Permalink
Replace calls to Method.GetCurrentMethod().Name with nameof() (#1943
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kant2002 authored Mar 21, 2023
1 parent 3e52e42 commit 1bcdb23
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
<DocumentationFile>$(OutputPath)\$(TargetFramework)\Microsoft.Data.SqlClient.xml</DocumentationFile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Product>Core $(BaseProduct)</Product>
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<NoWarn>$(NoWarn);IL2026;IL2057;IL2067;IL2070;IL2072;IL2075;IL2077;IL2080;IL2093;IL2111</NoWarn>
</PropertyGroup>
<PropertyGroup>
<DebugType>portable</DebugType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal sealed partial class SqlConfigurableRetryLogicLoader
/// <returns>Resolved type if it could resolve the type; otherwise, the `SqlConfigurableRetryFactory` type.</returns>
private static Type LoadType(string fullyQualifiedName)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(LoadType);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Entry point.", TypeName, methodName);

var result = Type.GetType(fullyQualifiedName, AssemblyResolver, TypeResolver);
Expand All @@ -48,7 +48,7 @@ private static Type LoadType(string fullyQualifiedName)
/// </summary>
private static string MakeFullPath(string directory, string assemblyName, string extension = ".dll")
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(MakeFullPath);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Looking for '{2}' assembly in '{3}' directory."
, TypeName, methodName, assemblyName, directory);
string fullPath = Path.Combine(directory, assemblyName);
Expand All @@ -60,7 +60,7 @@ private static string MakeFullPath(string directory, string assemblyName, string

private static Assembly AssemblyResolver(AssemblyName arg)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(AssemblyResolver);

string fullPath = MakeFullPath(Environment.CurrentDirectory, arg.Name);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Looking for '{2}' assembly by '{3}' full path."
Expand All @@ -76,7 +76,7 @@ private static Assembly AssemblyResolver(AssemblyName arg)
/// </summary>
private static Assembly Default_Resolving(AssemblyLoadContext arg1, AssemblyName arg2)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(Default_Resolving);

string target = MakeFullPath(Environment.CurrentDirectory, arg2.Name);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Looking for '{2}' assembly that is requested by '{3}' ALC from '{4}' path."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ private static Socket Connect(string serverName, int port, TimeSpan timeout, boo
catch (Exception e)
{
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNITCPHandle), EventType.ERR, "THIS EXCEPTION IS BEING SWALLOWED: {0}", args0: e?.Message);
SqlClientEventSource.Log.TryAdvancedTraceEvent($"{nameof(SNITCPHandle)}.{System.Reflection.MethodBase.GetCurrentMethod().Name}{EventType.ERR}THIS EXCEPTION IS BEING SWALLOWED: {e}");
SqlClientEventSource.Log.TryAdvancedTraceEvent($"{nameof(SNITCPHandle)}.{nameof(Connect)}{EventType.ERR}THIS EXCEPTION IS BEING SWALLOWED: {e}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Configuration;
using System.Reflection;

namespace Microsoft.Data.SqlClient
{
Expand All @@ -20,7 +19,7 @@ internal sealed class SqlAppContextSwitchManager
/// </summary>
internal static void ApplyContextSwitches(IAppContextSwitchOverridesSection appContextSwitches)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(ApplyContextSwitches);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Entry point.", TypeName, methodName);
if (appContextSwitches != null)
{
Expand All @@ -32,7 +31,7 @@ internal static void ApplyContextSwitches(IAppContextSwitchOverridesSection appC

private static bool ApplySwitchValues(string[] switches)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(ApplySwitchValues);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Entry point.", TypeName, methodName);

if (switches == null || switches.Length == 0 || switches.Length % 2 == 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal sealed partial class SqlConfigurableRetryLogicLoader
/// <returns>Resolved type if it could resolve the type; otherwise, the `SqlConfigurableRetryFactory` type.</returns>
private static Type LoadType(string fullyQualifiedName)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(LoadType);

var result = Type.GetType(fullyQualifiedName);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> The '{2}' type is resolved."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ namespace Microsoft.Data.SqlClient
{
internal static partial class LocalAppContextSwitches
{
private const string TypeName = nameof(LocalAppContextSwitches);
internal const string MakeReadAsyncBlockingString = @"Switch.Microsoft.Data.SqlClient.MakeReadAsyncBlocking";
internal const string LegacyRowVersionNullString = @"Switch.Microsoft.Data.SqlClient.LegacyRowVersionNullBehavior";
internal const string SuppressInsecureTLSWarningString = @"Switch.Microsoft.Data.SqlClient.SuppressInsecureTLSWarning";
Expand All @@ -30,7 +29,7 @@ static LocalAppContextSwitches()
catch (Exception e)
{
// Don't throw an exception for an invalid config file
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO>: {2}", TypeName, MethodBase.GetCurrentMethod().Name, e);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.ctor|INFO>: {1}", nameof(LocalAppContextSwitches), e);
}
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

using System;
using System.Configuration;
using System.Reflection;

namespace Microsoft.Data.SqlClient
{
Expand All @@ -21,7 +20,7 @@ internal sealed class AppConfigManager
/// <returns>The specified `T` object or default value of `T` if the section doesn't exist.</returns>
public static T FetchConfigurationSection<T>(string name)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(FetchConfigurationSection);

object section = null;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ public override bool TryNextInterval(out TimeSpan intervalTime)
RetryIntervalEnumerator.MoveNext();
intervalTime = RetryIntervalEnumerator.Current;
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Next gap time will be '{2}' before the next retry number {3}",
TypeName, MethodBase.GetCurrentMethod().Name, intervalTime, Current);
TypeName, nameof(TryNextInterval), intervalTime, Current);
}
else
{
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Current retry ({2}) has reached the maximum attempts (total attempts excluding the first run = {3}).",
TypeName, MethodBase.GetCurrentMethod().Name, Current, NumberOfTries - 1);
TypeName, nameof(TryNextInterval), Current, NumberOfTries - 1);
}
return result;
}
Expand All @@ -89,7 +89,7 @@ public override bool RetryCondition(object sender)
&& (PreCondition == null || PreCondition.Invoke(command.CommandText)); // if it contains an invalid command to retry

SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> (retry condition = '{2}') Avoids retry if it runs in a transaction or is skipped in the command's statement checking.",
TypeName, MethodBase.GetCurrentMethod().Name, result);
TypeName, nameof(RetryCondition), result);
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -192,15 +191,15 @@ private Exception CreateException(IList<Exception> exceptions, SqlRetryLogicBase
if (!manualCancellation)
{
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|ERR|THROW> Exiting retry scope (exceeded the max allowed attempts = {2}).",
TypeName, MethodBase.GetCurrentMethod().Name, retryLogic.NumberOfTries);
TypeName, nameof(CreateException), retryLogic.NumberOfTries);
}
_retryLogicPool.Add(retryLogic);
return result;
}

private void ApplyRetryingEvent(object sender, SqlRetryLogicBase retryLogic, TimeSpan intervalTime, List<Exception> exceptions, Exception lastException)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(ApplyRetryingEvent);
if (Retrying != null)
{
var retryEventArgs = new SqlRetryingEventArgs(retryLogic.Current, intervalTime, exceptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;

namespace Microsoft.Data.SqlClient
{
Expand Down Expand Up @@ -123,7 +122,7 @@ private static bool TransientErrorsCondition(Exception e, IEnumerable<int> retri
}
if (retriable)
{
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|ERR|CATCH> Found a transient error: number = <{2}>, message = <{3}>", nameof(SqlConfigurableRetryFactory), MethodBase.GetCurrentMethod().Name, item.Number, item.Message);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|ERR|CATCH> Found a transient error: number = <{2}>, message = <{3}>", nameof(SqlConfigurableRetryFactory), nameof(TransientErrorsCondition), item.Number, item.Message);
result = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public SqlConfigurableRetryLogicLoader(ISqlConfigurableRetryConnectionSection co

private static SqlRetryLogicBaseProvider CreateRetryLogicProvider(string sectionName, ISqlConfigurableRetryConnectionSection configSection)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(CreateRetryLogicProvider);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Entry point.", TypeName, methodName);

try
Expand Down Expand Up @@ -102,7 +102,7 @@ private static SqlRetryLogicBaseProvider CreateRetryLogicProvider(string section

private static SqlRetryLogicBaseProvider ResolveRetryLogicProvider(string configurableRetryType, string retryMethod, SqlRetryLogicOption option)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(ResolveRetryLogicProvider);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Entry point.", TypeName, methodName);

if (string.IsNullOrEmpty(retryMethod))
Expand Down Expand Up @@ -156,7 +156,7 @@ private static SqlRetryLogicBaseProvider ResolveRetryLogicProvider(string config

private static object CreateInstance(Type type, string retryMethodName, SqlRetryLogicOption option)
{
string methodName = MethodBase.GetCurrentMethod().Name;
string methodName = nameof(CreateInstance);
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Entry point.", TypeName, methodName);

if (type == typeof(SqlConfigurableRetryFactory) || type == null)
Expand Down Expand Up @@ -257,7 +257,7 @@ private static object[] PrepareParamValues(ParameterInfo[] parameterInfos, SqlRe
}
}
SqlClientEventSource.Log.TryTraceEvent("<sc.{0}.{1}|INFO> Parameters are prepared to invoke the `{2}.{3}()` method."
, TypeName, MethodBase.GetCurrentMethod().Name, typeof(SqlConfigurableRetryFactory).FullName, retryMethod);
, TypeName, nameof(PrepareParamValues), typeof(SqlConfigurableRetryFactory).FullName, retryMethod);
return funcParams;
}

Expand Down

0 comments on commit 1bcdb23

Please sign in to comment.