Files
codeql/csharp/ql/src/Useless code/RedundantToStringCall.ql
2019-01-02 12:59:07 +01:00

22 lines
598 B
Plaintext

/**
* @name Redundant ToString() call
* @description Explicit calls to `ToString()` can be removed when the call
* appears in a context where an implicit conversion exists.
* @kind problem
* @problem.severity recommendation
* @precision high
* @id cs/useless-tostring-call
* @tags maintainability
* useless-code
*/
import csharp
import semmle.code.csharp.commons.Strings
import semmle.code.csharp.frameworks.System
from MethodCall mc
where
mc instanceof ImplicitToStringExpr and
mc.getTarget() instanceof ToStringMethod
select mc, "Redundant call to 'ToString'."