Skip to content

Commit 9e4ac8b

Browse files
authored
File.Exists() is not null when true (#44310)
* File.Exists() is not null when true * Fix compile * Fix compile 2
1 parent ce4772d commit 9e4ac8b

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void Delete(string path, bool recursive) { }
2323
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern) { throw null; }
2424
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, System.IO.EnumerationOptions enumerationOptions) { throw null; }
2525
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, System.IO.SearchOption searchOption) { throw null; }
26-
public static bool Exists(string? path) { throw null; }
26+
public static bool Exists([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] string? path) { throw null; }
2727
public static System.DateTime GetCreationTime(string path) { throw null; }
2828
public static System.DateTime GetCreationTimeUtc(string path) { throw null; }
2929
public static string GetCurrentDirectory() { throw null; }

src/libraries/System.IO.FileSystem/src/System/IO/File.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Buffers;
66
using System.Collections.Generic;
77
using System.Diagnostics;
8+
using System.Diagnostics.CodeAnalysis;
89
using System.IO;
910
using System.Runtime.ExceptionServices;
1011
using System.Runtime.Versioning;
@@ -114,7 +115,7 @@ public static void Delete(string path)
114115
// given by the specified path exists; otherwise, the result is
115116
// false. Note that if path describes a directory,
116117
// Exists will return true.
117-
public static bool Exists(string? path)
118+
public static bool Exists([NotNullWhen(true)] string? path)
118119
{
119120
try
120121
{

src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Security;
78
using System.IO;
89

@@ -18,7 +19,7 @@ internal static partial class File
1819
// given by the specified path exists; otherwise, the result is
1920
// false. Note that if path describes a directory,
2021
// Exists will return true.
21-
public static bool Exists(string? path)
22+
public static bool Exists([NotNullWhen(true)] string? path)
2223
{
2324
try
2425
{

0 commit comments

Comments
 (0)