Skip to content

Add analyzer for StringBuilder(char) #46103

Closed as not planned
Closed as not planned

Description

@eduherminio

Context:

  • Adding a StringBuilder(char) constructor was originally proposed in Add StringBuilder(Char) #20848 due to the existing StringBuilder(int capacity) constructor accepting a char as an argument (i.e.: StringBuilder('a')), but the proposal was finally rejected.

  • Since this scenario will generally denote a bug, the possibility of creating an analyzer for it was brought up during the review of the proposal, but apparently was discarded or never formalized.

  • After opening a GH discussion about it, I was suggested in to formally propose the creation of such analyzer (StringBuilder: char constructor #46052 (comment)).

Activity

  1. added
    untriaged
    on Dec 15, 2020
  2. Dotnet-GitSync-Bot commented on Dec 15, 2020

    @Dotnet-GitSync-Bot
    Collaborator

    I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

  3. added
    code-fixer
    code-analyzer
    and removed
    code-fixer
    on Dec 15, 2020
  4. GrabYourPitchforks commented on Dec 16, 2020

    @GrabYourPitchforks
    Member

    I wonder if this can be turned into a generalized heuristic. Some possible examples:

    If the parameter is named capacity, count, or similar; and if the input to the parameter is a char which has been auto-widened to an int; trigger the analyzer.

    If there are two method overloads MyMethod(..., string, ...) and MyMethod(..., int, ...) (but no MyMethod(..., char, ...)), and if the call site matched the second overload because a char was auto-widened to an int, trigger the analyzer.

  5. removed
    untriaged
    on Jul 12, 2021
  6. added this to the Future milestone on Jul 12, 2021
  7. added
    api-suggestion
    on Mar 13, 2024
  8. tannergooding commented on Jul 11, 2026

    @tannergooding
    Member

    This has shown very little interest and is unlikely to happen given the size of the backlog and number of requests we get.

    While it is a quirk and potential issue for some APIs, it should be relatively quickly got given even basic tests and so is likely not a huge issue in practice.

  9. locked and limited conversation to collaborators on Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionarea-System.Runtimecode-analyzer

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions