Skip to content

Conversation

@DoctorKrolic
Copy link
Contributor

Closes: #37653

@DoctorKrolic DoctorKrolic requested a review from a team as a code owner May 29, 2025 10:38
@dotnet-policy-service dotnet-policy-service bot added Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode labels May 29, 2025
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\VisualBasicWorkspaceExtensions.projitems*{57ca988d-f010-4bf2-9a2e-07d6dcd2ff2c}*SharedItemsImports = 5
src\Analyzers\CSharp\Tests\CSharpAnalyzers.UnitTests.projitems*{58969243-7f59-4236-93d0-c93b81f569b3}*SharedItemsImports = 13
src\Dependencies\Collections\Microsoft.CodeAnalysis.Collections.projitems*{5f8d2414-064a-4b3a-9b42-8e2a04246be5}*SharedItemsImports = 5
src\Dependencies\Contracts\Microsoft.CodeAnalysis.Contracts.projitems*{5f8d2414-064a-4b3a-9b42-8e2a04246be5}*SharedItemsImports = 5
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As soon as I edit something in VS it adds this. So maybe just keep it?

[InlineData("ThrowIfLessThanOrEqual(num, 3)")]
[InlineData("ThrowIfEqual(num, 15)")]
[InlineData("ThrowIfNotEqual(num, 10)")]
[InlineData("ThrowIfZero(num)")]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although we have refactorrings only for ThrowIfNegative and ThrowIfNegativeOrZero as the most common ones we recognize other numeric checks as well since adding our own if one of this is present doesn't make much sense

{
private const string s_isPrefix = "Is";
private const string s_throwIfPrefix = "ThrowIf";
private const string IsPrefix = "Is";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

VS was constantly yelling at me for naming style violations. In this case I agreed (s_ is for static readonly and pascal case is for consts)

var throwIfNullMethod = argumentNullExceptionType
.GetMembers(s_throwIfNullName)
.OfType<IMethodSymbol>()
.FirstOrDefault(m => m.Parameters is [{ Type.SpecialType: SpecialType.System_Object }, ..]);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need to double-filter, allocate additional IEnumerable and so on

{
var text = methodName switch
{
nameof(string.IsNullOrEmpty) => new LocalizableResourceString(nameof(FeaturesResources._0_cannot_be_null_or_empty), FeaturesResources.ResourceManager, typeof(FeaturesResources)).ToString(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand the move with creating a localizable string and then immideatelly invoking ToString on it. This should be the same as just accessing the resource directly. Am I correct?

@CyrusNajmabadi
Copy link
Member

Thanks!

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

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee. VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactoring to generate ArgumentOutOfRange checks on numeric types

3 participants