Skip to content

Use char overloads to Join/Index strings #56531

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

Merged
merged 1 commit into from
Jul 19, 2024

Conversation

martincostello
Copy link
Member

Use char overloads to Join/Index strings

Use overloads that take a char for single-character strings.

Description

Use overloads that take a char for single-character strings where relevant with string.Join() or {Last}IndexOf() to resolve a number of analyser suggestions.

Also fixes a few IDE0055 diagnostics.

@ghost ghost added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jun 30, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 30, 2024
@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jul 8, 2024
@martincostello martincostello removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jul 8, 2024
@martincostello martincostello reopened this Jul 8, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 9.0-preview7 milestone Jul 8, 2024
Use overloads that take a `char` for single-character strings.
@amcasey
Copy link
Member

amcasey commented Jul 15, 2024

CI failure looks unrelated - that analyzer has been failing in a lot of runs.

Edit: Oh fancy, we have a bot to tag known failures now?

@@ -179,17 +179,17 @@ public static BindingAddress Parse(string address)
}
}

pathDelimiterStart = address.IndexOf(":", schemeDelimiterEnd + unixPipeHostPrefixLength, StringComparison.Ordinal);
Copy link
Member

Choose a reason for hiding this comment

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

Not your fault, but it seems very weird that the char version doesn't (AFAICT) accept a StringComparison. I'm assuming the default is Ordinal?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll double-check this one locally in an IDE.

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find one a char, int, StringComparison overload.

The IDE code-fixer also suggests exactly what's here:

image

I'm gonna guess that it does an ordinal check anyway and in this case as it's punctuation it's moot.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I should have been clearer - there isn't a better overload you could have called. I don't know why that is, but you don't need to do anything about it.

I just confirmed in the source that the default comparison is Ordinal so the change looks correct (if, sadly, less explicit).

@amcasey amcasey enabled auto-merge (squash) July 15, 2024 21:03
@amcasey
Copy link
Member

amcasey commented Jul 15, 2024

/azp run

Copy link

Azure Pipelines successfully started running 3 pipeline(s).

auto-merge was automatically disabled July 19, 2024 07:28

Pull request was closed

@amcasey amcasey enabled auto-merge (squash) July 19, 2024 14:35
@amcasey amcasey merged commit dfc5189 into dotnet:main Jul 19, 2024
27 checks passed
@martincostello martincostello deleted the use-char-overloads branch July 19, 2024 16:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants