I am getting a ReSharper (2018.1) warning for Possible 'System.NullReferenceException'
when I check for null implicitly with if (obj)
instead of if (obj ! = null)
.
For example:
using JetBrains.Annotations;
using UnityEngine.UI;
public class CanBeNullTest : MonoBehaviour
{
[CanBeNull] public Button Button { get; set; }
private void EnableButton_explicitCheck()
{
if (Button != null) Button.enabled = true;
}
private void EnableButton_implicitCheck()
{
if (Button) Button.enabled = true;
}
//private void EnableButton_cSharp6()
//{
// // null propagating operator is not available in C# 4
// Button?.enabled = true;
//}
}
Only the implicit null check shows the ReSharper warning:
I looked at the ReSharper page for "Why is ReSharper suggesting this" and the links there, but I couldn't find an explanation for this.
Is this a ReSharper limitation? Or is it incorrect or bad style to check for null implicitly?