Hi,
Love Gendarme, great work!
I've found that it's giving me false positives, epecially for the rule
'CheckParametersNullityInVisibleMethodsRule'.
To be fair, Gendarme is correct in what it's reporting as I wrap 'if
(arg==null) throw .... in a wrapper. e.g.
public XmlWrapper(XNode xml)
{
Guard.ArgumentNotNull( @"xml", xml );
...
Guard.ArgumentNotNull looke like (in it's plain form, I'll explain in
a bit!):
public static void ArgumentNotNull( string argName, object
argValue)
{
if ( argValue == null )
{
throw new ArgumentNullException( argName );
}
}
Now, it'd be very difficult for Gendarme (and other code analysis
tools) to figure out what's intended here (throw an exception if the
parameter is null).
Here's the crux of my post:
I use ReSharer a lot, and that has a set of attributes that give hints
as to what you intend, so for the method above, with attributes, it
looks like:
[AssertionMethod]
public static void ArgumentNotNull(
[InvokerParameterName] string argName,
[AssertionCondition( AssertionConditionType.IS_NOT_NULL)]
object argValue)
{
if ( argValue == null )
{
throw new ArgumentNullException( argName );
}
}
[AssertionMethod] means this method asserts something
[AssertionCondition] is the actual condition
[InvokerParameterName] is not related to this issue (it helps R#
ensure that the string passed representing a parameter name is an
actual parameter)
It would be great if there were a set of common code analysis
annotations that could be shared between all the code analysis tools
(R#, Gendarme, FxCop etc.)
As well as the R# annotations, I've seen others (like Lokad) extend
these with attributes for types that should be treated as immutable).
What do you think?
Cheers,
Steve
http://dunnhq.com