Is possible to declare any attribute to inform that a (bool)property handles the null check for other given property? #89352
-
Take this code as example: #nullable enable
public string? FilePath { get; private set; }
public bool IsFileLoaded => !string.IsNullOrWhiteSpace(FilePath);
public void ReloadFile()
{
if (!IsFileLoaded) return;
var file = File.OpenRead(FilePath);
} The compiler will warn about [IsNotNullCheck(nameof(FilePath))]
public bool IsFileLoaded => !string.IsNullOrWhitespace(FilePath);
[IsNullCheck(nameof(FilePath))]
public bool IsFileNotLoaded => string.IsNullOrWhitespace(FilePath); So, on this case if use |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
You can use |
Beta Was this translation helpful? Give feedback.
-
Side note: I wouldn't consider a file "loaded" if only the file name was set. "Named", maybe. |
Beta Was this translation helpful? Give feedback.
You can use
[MemberNotNullWhen]
on theIsFileLoaded
property.