org.sonar.plugins.csharp.S2325.html Maven / Gradle / Ivy
Why is this an issue?
Methods and properties that don’t access instance data can be static
to prevent any misunderstanding about the contract of the
method.
Noncompliant code example
public class Utilities
{
public int MagicNum // Noncompliant
{
get
{
return 42;
}
}
private static string magicWord = "please";
public string MagicWord // Noncompliant
{
get
{
return magicWord;
}
set
{
magicWord = value;
}
}
public int Sum(int a, int b) // Noncompliant
{
return a + b;
}
}
Compliant solution
public class Utilities
{
public static int MagicNum
{
get
{
return 42;
}
}
private static string magicWord = "please";
public static string MagicWord
{
get
{
return magicWord;
}
set
{
magicWord = value;
}
}
public static int Sum(int a, int b)
{
return a + b;
}
}
Exceptions
Methods with the following names are excluded because they can’t be made static
:
- Application_AuthenticateRequest
- Application_BeginRequest
- Application_End
- Application_EndRequest
- Application_Error
- Application_Init
- Application_Start
- Session_End
- Session_Start
© 2015 - 2025 Weber Informatics LLC | Privacy Policy