Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for RemoveRedundantToStringCall(RCS1097) #1037

Merged
merged 4 commits into from
Feb 26, 2023

Conversation

jamesHargreaves12
Copy link
Contributor

Current behaviour:

  • RCS1097 suggest removing ToString for structs which can lead to boxing.

It looks as if this was attempted to be prevented by using an IsReferenceType check at:
https://github.com/JosefPihrt/Roslynator/blob/3c6f1c1fc24b63aea6b0d82e64ec4e02d9ca39ad/src/Analyzers/CSharp/Analysis/RemoveRedundantToStringCallAnalysis.cs#L60

Unfortunately, this doesn't work for structs as they have type System.ValueType which is considered a reference type. See
https://learn.microsoft.com/en-us/dotnet/api/system.type.isvaluetype?redirectedfrom=MSDN&view=net-7.0#System_Type_IsValueType

Fix implemented just explicitly checks for System_ValueType.

Also added a test to catch future regressions.

@josefpihrt
Copy link
Collaborator

Hi,

thanks for the PR, I just made some minor comments.

jamesHargreaves12 and others added 2 commits February 15, 2023 21:07
…sts.cs

Co-authored-by: Josef Pihrt <josef@pihrt.net>
…sts.cs

Co-authored-by: Josef Pihrt <josef@pihrt.net>
@josefpihrt josefpihrt merged commit 4ff1606 into dotnet:main Feb 26, 2023
Haarmees pushed a commit to Haarmees/Roslynator that referenced this pull request Oct 30, 2023
Co-authored-by: Josef Pihrt <josef@pihrt.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants