Skip to content

False positives in csharp for useless-tostring-call #21722

Description

@rvdginste

Description of the false positive

I see two contexts in which this generates a false positive:

  • override of ToString() that calls base.ToString()
  • ToString() call inside the argument to StringBuilder.AppendLine(...)

Code samples or links to source code

public class Test : BaseTest
{
    public override string ToString()
        => $"Test class ToString; TestBase: {base.ToString()}";
}
public class Test
{
   public EnumType Prop { get; set; }

  public override string ToString()
  {
    StringBuilder sb = new();
    sb.AppendLine(Prop.ToString());
    return sb.ToString();
  }
}

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions