Possible NullReferenceException and Value Analysis

The following code causes ReSharper (3.0.2) to highlight the second reference to 'group' (Check.Require(group.Id..) as a possible null reference exception.

public void Create(Group group)
{
Check.Require(group != null, "group must not be null", log);
Check.Require(group.Id == 0, "group must be new", log);

It would be nice if the value analysis used to detect possible null references could be enhanced to allow a user-defined pattern (for example, in my case, the 'Check.Require(group != null...' .

I've been told that this is possible with Value Analysis, but can't find any examples. Having played around with adding the method as an assertion I can see an effect, but not the one I'm looking for.

Can anyone provide an example of how to set this up?

Andy.

1 comment
Comment actions Permalink

You have to tell ReSharper to count this method as "assrtion method"
Please visit the options
ReSharper->Options->Code Inspection->Value Analysis, and add your method to
the list

--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Andy Hitchman" <andy@solutionarchitects.com.au> wrote in message
news:18078347.1189642722867.JavaMail.itn@is.intellij.net...

The following code causes ReSharper (3.0.2) to highlight the second
reference to 'group' (Check.Require(group.Id..) as a possible null
reference exception.

>

public void Create(Group group)
{
Check.Require(group != null, "group must not be null", log);
Check.Require(group.Id == 0, "group must be new", log);

>

It would be nice if the value analysis used to detect possible null
references could be enhanced to allow a user-defined pattern (for example,
in my case, the 'Check.Require(group != null...' .

>

I've been told that this is possible with Value Analysis, but can't find
any examples. Having played around with adding the method as an assertion
I can see an effect, but not the one I'm looking for.

>

Can anyone provide an example of how to set this up?

>

Andy.



0

Please sign in to leave a comment.