From 9e4ac8bac88b4abf35825e116007f04df2e92b3c Mon Sep 17 00:00:00 2001 From: Ilya Date: Fri, 6 Nov 2020 01:57:46 +0500 Subject: [PATCH] File.Exists() is not null when true (#44310) * File.Exists() is not null when true * Fix compile * Fix compile 2 --- src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs | 2 +- src/libraries/System.IO.FileSystem/src/System/IO/File.cs | 3 ++- src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs b/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs index f84978d..c1790b0 100644 --- a/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs +++ b/src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs @@ -23,7 +23,7 @@ namespace System.IO public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern) { throw null; } public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, System.IO.EnumerationOptions enumerationOptions) { throw null; } public static System.Collections.Generic.IEnumerable EnumerateFileSystemEntries(string path, string searchPattern, System.IO.SearchOption searchOption) { throw null; } - public static bool Exists(string? path) { throw null; } + public static bool Exists([System.Diagnostics.CodeAnalysis.NotNullWhen(true)] string? path) { throw null; } public static System.DateTime GetCreationTime(string path) { throw null; } public static System.DateTime GetCreationTimeUtc(string path) { throw null; } public static string GetCurrentDirectory() { throw null; } diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs index 1b089a91..9f59754 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/File.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/File.cs @@ -5,6 +5,7 @@ using System; using System.Buffers; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.IO; using System.Runtime.ExceptionServices; using System.Runtime.Versioning; @@ -114,7 +115,7 @@ namespace System.IO // given by the specified path exists; otherwise, the result is // false. Note that if path describes a directory, // Exists will return true. - public static bool Exists(string? path) + public static bool Exists([NotNullWhen(true)] string? path) { try { diff --git a/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs b/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs index 56f85c7..b3aa37a 100644 --- a/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs +++ b/src/libraries/System.Private.CoreLib/src/Internal/IO/File.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; using System.Security; using System.IO; @@ -18,7 +19,7 @@ namespace Internal.IO // given by the specified path exists; otherwise, the result is // false. Note that if path describes a directory, // Exists will return true. - public static bool Exists(string? path) + public static bool Exists([NotNullWhen(true)] string? path) { try { -- 2.7.4