ReSharper is clever enough to know that a string.Format requires a not-null format argument so it warns me about it when I simply write
_message = string.Format(messageFormat, args);
where messageFormat can indeed be null. As soon as I add a condition for this variable:
if (!string.IsNullOrEmpty(messageFormat))
{
_message = string.Format(messageFormat, args);
}
the warning disappears. Unfortunately it doesn't when I use an extension method:
if (messageFormat.IsNotNullOrEmpty())
{
_message = string.Format(messageFormat, args); // possible 'null' assignment warning
}
My question is: is there a way to teach ReSharper that my extension method has the same meaning as !string.IsNullOrEmpty(messageFormat)?
The extension is defined as:
public static bool IsNotNullOrEmpty([CanBeNull] this string value) => !IsNullOrEmpty(value);

