Background and Motivation
Found when annotating roslyn. These methods should never return true for null.
Proposed API
namespace System.IO
{
public static class Directory {
- public static bool Exists(string? path);
+ public static bool Exists([NotNullWhen(true)] string? path);
}
public static class File {
- public static bool Exists(string? path);
+ public static bool Exists([NotNullWhen(true)] string? path);
}
}
Usage Examples
string? path = ...
if (Directory.Exists(path))
{
var subDirectories = Directory.GetDirectories(path); // no warning
}
Alternative Designs
None.
Risks
I couldn't imagine how they can return true for null.