0

Annotation to prevent "possible null reference exception" warning?

I'm trying to figure out how to annotate a null checking method so code that follows it is not marked as a possible null reference exception.

For example:

public bool IsNull(object value)
{
return value == null;
}

public void DoSomething()
{
object someValue = null;
if(IsNull(someValue))
Console.WriteLine("someValue is null");
else
Console.WriteLine("someValue = " + someValue.ToString());
}

Today, ReSharper marks "someValue" in the else block as a possible null reference exception even though it can logically never be null.

Is it possible to annotate the IsNull method somehow to prevent this?
Is there an alternate solution?


I posted a similar question in May that went unanswered at
.

TIA,
shovavnik

17 comments

Please sign in to leave a comment.