-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Correctness.MethodCanBeMadeStaticRule(2.10)
Sebastien Pouliot edited this page Jan 22, 2011
·
2 revisions
Assembly: Gendarme.Rules.Correctness
Version: 2.10
This rule checks for methods that do not require anything from the current instance. Those methods can be converted into static methods, which helps a bit with performance (the hidden this parameter can be omitted), and clarifies the API.
Bad example:
public class Bad {
private int x, y, z;
bool Valid (int value)
{
// no instance members are used
return (value > 0);
}
public int X {
get {
return x;
}
set {
if (!Valid (value)) {
throw ArgumentException ("X");
}
x = value;
}
}
// same for Y and Z
}
Good example:
public class Good {
private int x, y, z;
static bool Valid (int value)
{
return (value > 0);
}
// same X (and Y and Z) as before
}
Note that this page was autogenerated (3/17/2011 9:31:58 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!