This is ReSharper 7 with Visual Studio 2012. With the sample below
// This code works fine and as expected and ReShrper is happy with it
if (!string.IsNullOrWhiteSpace(extension) && extension.Length == 3)
{
// do something
}
// ReSharper highlights "extension" in extension.Length with "Possible 'System.NullReferenceException'"
if (!extension.IsNullOrWhiteSpace() && extension.Length == 3)
{
// do something
}
And, I have created the following extension method:
public static class StringExtensions
{
public static bool IsNullOrWhiteSpace(this string s)
{
return string.IsNullOrWhiteSpace(s);
}
}
I looked at the reflected code of String.IsNullOrWhiteSpace
and it doesn't have any related code or attribute that would highlight to R# that the check is verified. Is this hardcoded in R#?
I looked at Code Contracts, but I am not sure it would help in my case.
Do you have a workaround for proving to ReSharper that the check condition is already verified by my extension method?