
org.sonar.plugins.csharp.S3236.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sonarlint-omnisharp-plugin Show documentation
Show all versions of sonarlint-omnisharp-plugin Show documentation
Code Analyzer based on Omnisharp
Why is this an issue?
Caller information attributes: CallerFilePathAttribute
, CallerLineNumberAttribute
, and
CallerArgumentExpressionAttribute
provide a way to get information about the caller of a method through optional parameters. But the
arguments for these optional parameters are only generated if they are not explicitly defined in the call. Thus, specifying the argument values
defeats the purpose of the attributes.
Noncompliant code example
void TraceMessage(string message,
[CallerFilePath] string filePath = null,
[CallerLineNumber] int lineNumber = 0)
{
/* ... */
}
void MyMethod()
{
TraceMessage("my message", "A.B.C.Foo.cs", 42); // Noncompliant
}
Compliant solution
void TraceMessage(string message,
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0)
{
/* ... */
}
void MyMethod()
{
TraceMessage("my message");
}
Exceptions
CallerMemberName
is not checked to avoid False-Positives with WPF/UWP applications.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy