-
Notifications
You must be signed in to change notification settings - Fork 468
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 to improve code fixer heuristic employed by CA1835 #4269
Conversation
Add new test cases to handle partial buffer read/write. Adjust existing test cases that use the full buffer to avoid adding the AsMemory invocation.
...s/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpPreferStreamAsyncMemoryOverloads.Fixer.cs
Outdated
Show resolved
Hide resolved
...s/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpPreferStreamAsyncMemoryOverloads.Fixer.cs
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/PreferStreamAsyncMemoryOverloads.Fixer.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/PreferStreamAsyncMemoryOverloads.Fixer.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/PreferStreamAsyncMemoryOverloads.Fixer.cs
Outdated
Show resolved
Hide resolved
...Analyzers/Core/Microsoft.NetCore.Analyzers/Runtime/PreferStreamAsyncMemoryOverloads.Fixer.cs
Outdated
Show resolved
Hide resolved
...sualBasic/Microsoft.NetCore.Analyzers/Runtime/BasicPreferStreamAsyncMemoryOverloads.Fixer.vb
Outdated
Show resolved
Hide resolved
...sualBasic/Microsoft.NetCore.Analyzers/Runtime/BasicPreferStreamAsyncMemoryOverloads.Fixer.vb
Outdated
Show resolved
Hide resolved
...sualBasic/Microsoft.NetCore.Analyzers/Runtime/BasicPreferStreamAsyncMemoryOverloads.Fixer.vb
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM. You can improve the heuristic by using SemanticModel.GetConstantValue API.
FYI I opened a proposal to suggest simplifying Edit: I moved it to the roslyn repo: dotnet/roslyn#48239 |
...s/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpPreferStreamAsyncMemoryOverloads.Fixer.cs
Outdated
Show resolved
Hide resolved
...s/CSharp/Microsoft.NetCore.Analyzers/Runtime/CSharpPreferStreamAsyncMemoryOverloads.Fixer.cs
Outdated
Show resolved
Hide resolved
...sualBasic/Microsoft.NetCore.Analyzers/Runtime/BasicPreferStreamAsyncMemoryOverloads.Fixer.vb
Outdated
Show resolved
Hide resolved
...sualBasic/Microsoft.NetCore.Analyzers/Runtime/BasicPreferStreamAsyncMemoryOverloads.Fixer.vb
Show resolved
Hide resolved
…the Value without having to cast to integer first. Use existing WellKnownMemberName instead "Length".
Thanks for improving this. |
* Shared Fixer: detect arguments 0 and buffer.Length. * CSharp fixer: Implement method that detects 0 and buffer.Length syntax nodes. * VB fixer: Implement method that detects 0 and buffer.Length syntax nodes. * Test data: Add new test cases to handle partial buffer read/write. Adjust existing test cases that use the full buffer to avoid adding the AsMemory invocation. * ReadAsync tests: Consume the new test data. * WriteAsync tests: Consume the new test data. * Suggestions by Evangelink. * Pass the semantic model to the syntax-specific method. * Adapt the C# syntax-specific method to take the semantic model instance. * Adapt the VB syntax-specific method to take the semantic model instance. * Fix some failing new test cases. * Update the unit tests. * Simplify check for 0 by directly using the constant pattern check on the Value without having to cast to integer first. Use existing WellKnownMemberName instead "Length". Co-authored-by: carlossanlop <carlossanlop@users.noreply.github.com>
Fixes #4235
For invocations of ReadAsync/WriteAsync that consider the full buffer (from
0
tobuffer.Length
):Instead of suggesting this:
We now want to suggest this: