-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.Correctness.CheckParametersNullityInVisibleMethodsRule(2.10)
Sebastien Pouliot edited this page Jan 22, 2011
·
2 revisions
Assembly: Gendarme.Rules.Correctness
Version: 2.10
This rule checks if all nullable parameters of visible methods are compared with '''null''' before they get used. This reduce the likelyhood of the runtime throwing a NullReferenceException.
Bad example:
[DllImport ("message")]
internal static extern byte [] Parse (string s, int length);
public bool TryParse (string s, out Message m)
{
// is 's' is null then 's.Length' will throw a NullReferenceException
// which a TryParse method should never do
byte [] data = Parse (s, s.Length);
if (data == null) {
m = null;
return false;
}
m = new Message (data);
return true;
}
Good example:
[DllImport ("message")]
internal static extern byte [] Parse (string s, int length);
public bool TryParse (string s, out Message m)
{
if (s == null) {
m = null;
return false;
}
byte [] data = Parse (s, s.Length);
if (data == null) {
m = null;
return false;
}
m = new Message (data);
return true;
}
- This rule is available since Gendarme 2.2
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!