Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.IO;
using System.Runtime.InteropServices;
Expand All @@ -12,11 +13,11 @@ internal partial class Kernel32
{
[DllImport(Libraries.Kernel32, EntryPoint = "ReplaceFileW", SetLastError = true, CharSet = CharSet.Unicode, BestFitMapping = false)]
private static extern bool ReplaceFilePrivate(
string replacedFileName, string replacementFileName, string backupFileName,
string replacedFileName, string replacementFileName, string? backupFileName,
int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved);

internal static bool ReplaceFile(
string replacedFileName, string replacementFileName, string backupFileName,
string replacedFileName, string replacementFileName, string? backupFileName,
int dwReplaceFlags, IntPtr lpExclude, IntPtr lpReserved)
{
replacedFileName = PathInternal.EnsureExtendedPrefixIfNeeded(replacedFileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
Expand All @@ -18,12 +19,12 @@ namespace System.IO
{
internal static partial class FileSystem
{
public static bool DirectoryExists(string fullPath)
public static bool DirectoryExists(string? fullPath)
{
return DirectoryExists(fullPath, out int lastError);
}

private static bool DirectoryExists(string path, out int lastError)
private static bool DirectoryExists(string? path, out int lastError)
{
Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data = default;
lastError = FillAttributeInfo(path, ref data, returnErrorOnNotFound: true);
Expand Down Expand Up @@ -52,7 +53,7 @@ public static bool FileExists(string fullPath)
/// <param name="path">The file path from which the file attribute information will be filled.</param>
/// <param name="data">A struct that will contain the attribute information.</param>
/// <param name="returnErrorOnNotFound">Return the error code for not found errors?</param>
internal static int FillAttributeInfo(string path, ref Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data, bool returnErrorOnNotFound)
internal static int FillAttributeInfo(string? path, ref Interop.Kernel32.WIN32_FILE_ATTRIBUTE_DATA data, bool returnErrorOnNotFound)
{
int errorCode = Interop.Errors.ERROR_SUCCESS;

Expand Down Expand Up @@ -97,7 +98,7 @@ internal static int FillAttributeInfo(string path, ref Interop.Kernel32.WIN32_FI
// cases that we know we don't want to retry on.

Interop.Kernel32.WIN32_FIND_DATA findData = default;
using (SafeFindHandle handle = Interop.Kernel32.FindFirstFile(path, ref findData))
using (SafeFindHandle handle = Interop.Kernel32.FindFirstFile(path!, ref findData))
{
if (handle.IsInvalid)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
Expand All @@ -18,7 +19,7 @@ namespace System.IO
{
internal static partial class FileSystem
{
public static unsafe void CreateDirectory(string fullPath, byte[] securityDescriptor = null)
public static unsafe void CreateDirectory(string fullPath, byte[]? securityDescriptor = null)
{
// We can save a bunch of work if the directory we want to create already exists. This also
// saves us in the case where sub paths are inaccessible (due to ERROR_ACCESS_DENIED) but the
Expand Down Expand Up @@ -126,7 +127,7 @@ public static unsafe void CreateDirectory(string fullPath, byte[] securityDescri
// Handle CreateDirectory("X:\\") when X: doesn't exist. Similarly for n/w paths.
if ((count == 0) && !somepathexists)
{
string root = Path.GetPathRoot(fullPath);
string? root = Path.GetPathRoot(fullPath);

if (!DirectoryExists(root))
{
Expand Down
5 changes: 3 additions & 2 deletions src/libraries/Common/src/System/Text/ValueUtf8Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Buffers;

namespace System.Text
Expand All @@ -13,7 +14,7 @@ namespace System.Text
/// </summary>
internal ref struct ValueUtf8Converter
{
private byte[] _arrayToReturnToPool;
private byte[]? _arrayToReturnToPool;
private Span<byte> _bytes;

public ValueUtf8Converter(Span<byte> initialBuffer)
Expand All @@ -40,7 +41,7 @@ public Span<byte> ConvertAndTerminateString(ReadOnlySpan<char> value)

public void Dispose()
{
byte[] toReturn = _arrayToReturnToPool;
byte[]? toReturn = _arrayToReturnToPool;
if (toReturn != null)
{
_arrayToReturnToPool = null;
Expand Down
48 changes: 24 additions & 24 deletions src/libraries/System.IO.FileSystem/ref/System.IO.FileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void Delete(string path, bool recursive) { }
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern) { throw null; }
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, System.IO.EnumerationOptions enumerationOptions) { throw null; }
public static System.Collections.Generic.IEnumerable<string> EnumerateFileSystemEntries(string path, string searchPattern, System.IO.SearchOption searchOption) { throw null; }
public static bool Exists(string path) { throw null; }
public static bool Exists(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; }
Expand All @@ -46,7 +46,7 @@ public static void Delete(string path, bool recursive) { }
public static System.DateTime GetLastWriteTime(string path) { throw null; }
public static System.DateTime GetLastWriteTimeUtc(string path) { throw null; }
public static string[] GetLogicalDrives() { throw null; }
public static System.IO.DirectoryInfo GetParent(string path) { throw null; }
public static System.IO.DirectoryInfo? GetParent(string path) { throw null; }
public static void Move(string sourceDirName, string destDirName) { }
public static void SetCreationTime(string path, System.DateTime creationTime) { }
public static void SetCreationTimeUtc(string path, System.DateTime creationTimeUtc) { }
Expand All @@ -61,7 +61,7 @@ public sealed partial class DirectoryInfo : System.IO.FileSystemInfo
public DirectoryInfo(string path) { }
public override bool Exists { get { throw null; } }
public override string Name { get { throw null; } }
public System.IO.DirectoryInfo Parent { get { throw null; } }
public System.IO.DirectoryInfo? Parent { get { throw null; } }
public System.IO.DirectoryInfo Root { get { throw null; } }
public void Create() { }
public System.IO.DirectoryInfo CreateSubdirectory(string path) { throw null; }
Expand Down Expand Up @@ -111,10 +111,10 @@ public static void AppendAllLines(string path, System.Collections.Generic.IEnume
public static void AppendAllLines(string path, System.Collections.Generic.IEnumerable<string> contents, System.Text.Encoding encoding) { }
public static System.Threading.Tasks.Task AppendAllLinesAsync(string path, System.Collections.Generic.IEnumerable<string> contents, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task AppendAllLinesAsync(string path, System.Collections.Generic.IEnumerable<string> contents, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static void AppendAllText(string path, string contents) { }
public static void AppendAllText(string path, string contents, System.Text.Encoding encoding) { }
public static System.Threading.Tasks.Task AppendAllTextAsync(string path, string contents, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task AppendAllTextAsync(string path, string contents, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static void AppendAllText(string path, string? contents) { }
public static void AppendAllText(string path, string? contents, System.Text.Encoding encoding) { }
public static System.Threading.Tasks.Task AppendAllTextAsync(string path, string? contents, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task AppendAllTextAsync(string path, string? contents, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.IO.StreamWriter AppendText(string path) { throw null; }
public static void Copy(string sourceFileName, string destFileName) { }
public static void Copy(string sourceFileName, string destFileName, bool overwrite) { }
Expand All @@ -125,7 +125,7 @@ public static void Copy(string sourceFileName, string destFileName, bool overwri
public static void Decrypt(string path) { }
public static void Delete(string path) { }
public static void Encrypt(string path) { }
public static bool Exists(string path) { throw null; }
public static bool Exists(string? path) { throw null; }
public static System.IO.FileAttributes GetAttributes(string path) { throw null; }
public static System.DateTime GetCreationTime(string path) { throw null; }
public static System.DateTime GetCreationTimeUtc(string path) { throw null; }
Expand Down Expand Up @@ -153,8 +153,8 @@ public static void Move(string sourceFileName, string destFileName, bool overwri
public static System.Threading.Tasks.Task<string> ReadAllTextAsync(string path, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Collections.Generic.IEnumerable<string> ReadLines(string path) { throw null; }
public static System.Collections.Generic.IEnumerable<string> ReadLines(string path, System.Text.Encoding encoding) { throw null; }
public static void Replace(string sourceFileName, string destinationFileName, string destinationBackupFileName) { }
public static void Replace(string sourceFileName, string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors) { }
public static void Replace(string sourceFileName, string destinationFileName, string? destinationBackupFileName) { }
public static void Replace(string sourceFileName, string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors) { }
public static void SetAttributes(string path, System.IO.FileAttributes fileAttributes) { }
public static void SetCreationTime(string path, System.DateTime creationTime) { }
public static void SetCreationTimeUtc(string path, System.DateTime creationTimeUtc) { }
Expand All @@ -170,16 +170,16 @@ public static void WriteAllLines(string path, string[] contents) { }
public static void WriteAllLines(string path, string[] contents, System.Text.Encoding encoding) { }
public static System.Threading.Tasks.Task WriteAllLinesAsync(string path, System.Collections.Generic.IEnumerable<string> contents, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task WriteAllLinesAsync(string path, System.Collections.Generic.IEnumerable<string> contents, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static void WriteAllText(string path, string contents) { }
public static void WriteAllText(string path, string contents, System.Text.Encoding encoding) { }
public static System.Threading.Tasks.Task WriteAllTextAsync(string path, string contents, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task WriteAllTextAsync(string path, string contents, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static void WriteAllText(string path, string? contents) { }
public static void WriteAllText(string path, string? contents, System.Text.Encoding encoding) { }
public static System.Threading.Tasks.Task WriteAllTextAsync(string path, string? contents, System.Text.Encoding encoding, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task WriteAllTextAsync(string path, string? contents, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
}
public sealed partial class FileInfo : System.IO.FileSystemInfo
{
public FileInfo(string fileName) { }
public System.IO.DirectoryInfo Directory { get { throw null; } }
public string DirectoryName { get { throw null; } }
public System.IO.DirectoryInfo? Directory { get { throw null; } }
public string? DirectoryName { get { throw null; } }
public override bool Exists { get { throw null; } }
public bool IsReadOnly { get { throw null; } set { } }
public long Length { get { throw null; } }
Expand All @@ -200,8 +200,8 @@ public void MoveTo(string destFileName, bool overwrite) { }
public System.IO.FileStream OpenRead() { throw null; }
public System.IO.StreamReader OpenText() { throw null; }
public System.IO.FileStream OpenWrite() { throw null; }
public System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName) { throw null; }
public System.IO.FileInfo Replace(string destinationFileName, string destinationBackupFileName, bool ignoreMetadataErrors) { throw null; }
public System.IO.FileInfo Replace(string destinationFileName, string? destinationBackupFileName) { throw null; }
public System.IO.FileInfo Replace(string destinationFileName, string? destinationBackupFileName, bool ignoreMetadataErrors) { throw null; }
public override string ToString() { throw null; }
}
public abstract partial class FileSystemInfo : System.MarshalByRefObject, System.Runtime.Serialization.ISerializable
Expand Down Expand Up @@ -266,19 +266,19 @@ public ref partial struct FileSystemEntry
}
public partial class FileSystemEnumerable<TResult> : System.Collections.Generic.IEnumerable<TResult>, System.Collections.IEnumerable
{
public FileSystemEnumerable(string directory, System.IO.Enumeration.FileSystemEnumerable<TResult>.FindTransform transform, System.IO.EnumerationOptions options = null) { }
public System.IO.Enumeration.FileSystemEnumerable<TResult>.FindPredicate ShouldIncludePredicate { get { throw null; } set { } }
public System.IO.Enumeration.FileSystemEnumerable<TResult>.FindPredicate ShouldRecursePredicate { get { throw null; } set { } }
public FileSystemEnumerable(string directory, System.IO.Enumeration.FileSystemEnumerable<TResult>.FindTransform transform, System.IO.EnumerationOptions? options = null) { }
public System.IO.Enumeration.FileSystemEnumerable<TResult>.FindPredicate? ShouldIncludePredicate { get { throw null; } set { } }
public System.IO.Enumeration.FileSystemEnumerable<TResult>.FindPredicate? ShouldRecursePredicate { get { throw null; } set { } }
public System.Collections.Generic.IEnumerator<TResult> GetEnumerator() { throw null; }
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { throw null; }
public delegate bool FindPredicate(ref System.IO.Enumeration.FileSystemEntry entry);
public delegate TResult FindTransform(ref System.IO.Enumeration.FileSystemEntry entry);
}
public abstract partial class FileSystemEnumerator<TResult> : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, System.Collections.Generic.IEnumerator<TResult>, System.Collections.IEnumerator, System.IDisposable
{
public FileSystemEnumerator(string directory, System.IO.EnumerationOptions options = null) { }
public FileSystemEnumerator(string directory, System.IO.EnumerationOptions? options = null) { }
public TResult Current { get { throw null; } }
object System.Collections.IEnumerator.Current { get { throw null; } }
object? System.Collections.IEnumerator.Current { get { throw null; } }
protected virtual bool ContinueOnError(int error) { throw null; }
public void Dispose() { }
protected virtual void Dispose(bool disposing) { }
Expand All @@ -293,6 +293,6 @@ public static partial class FileSystemName
{
public static bool MatchesSimpleExpression(System.ReadOnlySpan<char> expression, System.ReadOnlySpan<char> name, bool ignoreCase = true) { throw null; }
public static bool MatchesWin32Expression(System.ReadOnlySpan<char> expression, System.ReadOnlySpan<char> name, bool ignoreCase = true) { throw null; }
public static string TranslateWin32Expression(string expression) { throw null; }
public static string TranslateWin32Expression(string? expression) { throw null; }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.IO.FileSystem.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<NoWarn>$(NoWarn);CS1573</NoWarn>
<IsPartialFacadeAssembly>true</IsPartialFacadeAssembly>
<Configurations>netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release</Configurations>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetsUnix)' == 'true'">
<NoWarn>$(NoWarn);414</NoWarn>
Expand Down
Loading