Skip to content

Replace calls to Method.GetCurrentMethod().Name with nameof()#1943

Merged
lcheunglci merged 4 commits into
dotnet:mainfrom
kant2002:kant/remove-currentmethod-usages
Mar 21, 2023
Merged

Replace calls to Method.GetCurrentMethod().Name with nameof()#1943
lcheunglci merged 4 commits into
dotnet:mainfrom
kant2002:kant/remove-currentmethod-usages

Conversation

@kant2002

@kant2002 kant2002 commented Mar 5, 2023

Copy link
Copy Markdown
Contributor

That reduce places which marked as trimmer unfriendly. Even if Method.CurrentMethod().Name will work after trimming, but tooling cannot decide that in generic cases, see: dotnet/runtime#53242 At this point I would like to replace formatting primitives with $"" if possible, since that allow Rolsyn build constant string for us at compile time.

Also enabled Trim Analyzer on the build, so all trim warnings can be gradually removed after proper annotations, or other work done.

/cc @Wraith2

That reduce places which marked as trimmer unfriendly. Even if `Method.CurrentMethod().Name` will work after trimming, but tooling cannot decide that in generic cases, see: dotnet/runtime#53242
At this point I would like to replace formatting primitives with `$""` if possible, since that allow Rolsyn manually build constant string.

Also enabled Trim Analyzer on the build, so all trim warnings can be gradually removed after proper annotations, or other work done.

/cc @Wraith2
{
// 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}.{1}|INFO>: {2}", TypeName, "..ctor", e);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be .cctor for a static constructor?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, can you inline the TypeName, it's a nameof in a variable which is a bit pointless when it's single use.

@DavoudEshtehari DavoudEshtehari added Code Health 💊 Issues/PRs that are targeted to source code quality improvements. and removed 💡 Enhancement labels Mar 15, 2023
@codecov

codecov Bot commented Mar 15, 2023

Copy link
Copy Markdown

Codecov Report

Patch coverage: 90.00% and project coverage change: -1.84 ⚠️

Comparison is base (73c6b2f) 71.53% compared to head (7d55d47) 69.69%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1943      +/-   ##
==========================================
- Coverage   71.53%   69.69%   -1.84%     
==========================================
  Files         306      306              
  Lines       61841    61563     -278     
==========================================
- Hits        44235    42909    -1326     
- Misses      17606    18654    +1048     
Flag Coverage Δ
addons 92.38% <ø> (ø)
netcore 73.20% <89.47%> (-2.50%) ⬇️
netfx 67.96% <100.00%> (-1.15%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...icrosoft/Data/SqlClient/LocalAppContextSwitches.cs 56.25% <0.00%> (ø)
...SqlClient/SqlAppContextSwitchManager.NetCoreApp.cs 23.80% <50.00%> (ø)
...ity/SqlConfigurableRetryLogicManager.NetCoreApp.cs 100.00% <100.00%> (ø)
...e/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs 61.85% <100.00%> (-0.78%) ⬇️
...ility/SqlConfigurableRetryLogicManager.LoadType.cs 100.00% <100.00%> (ø)
...oft/Data/SqlClient/Reliability/AppConfigManager.cs 68.57% <100.00%> (ø)
...Data/SqlClient/Reliability/Common/SqlRetryLogic.cs 100.00% <100.00%> (ø)
...Client/Reliability/Common/SqlRetryLogicProvider.cs 89.13% <100.00%> (-2.18%) ⬇️
...lClient/Reliability/SqlConfigurableRetryFactory.cs 100.00% <100.00%> (ø)
...ent/Reliability/SqlConfigurableRetryLogicLoader.cs 85.48% <100.00%> (ø)

... and 42 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lcheunglci

Copy link
Copy Markdown
Contributor

The changes looks good to me. Thanks @kant2002 for your contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code Health 💊 Issues/PRs that are targeted to source code quality improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants