Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate System.IO.FileSystem.DriveInfo for nullable reference types #464

Merged
merged 2 commits into from
Dec 5, 2019
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 @@ -163,14 +163,12 @@ private static extern unsafe int GetFormatInfoForMountPoint(

internal static int GetFormatInfoForMountPoint(string name, out string format)
{
DriveType temp;
return GetFormatInfoForMountPoint(name, out format, out temp);
return GetFormatInfoForMountPoint(name, out format, out _);
}

internal static int GetFormatInfoForMountPoint(string name, out DriveType type)
{
string temp;
return GetFormatInfoForMountPoint(name, out temp, out type);
return GetFormatInfoForMountPoint(name, out _, out type);
}

private static int GetFormatInfoForMountPoint(string name, out string format, out DriveType type)
Expand All @@ -184,8 +182,8 @@ private static int GetFormatInfoForMountPoint(string name, out string format, ou
{
// Check if we have a numeric answer or string
format = numericFormat != -1 ?
Enum.GetName(typeof(UnixFileSystemTypes), numericFormat) :
Marshal.PtrToStringAnsi((IntPtr)formatBuffer);
Enum.GetName(typeof(UnixFileSystemTypes), numericFormat) ?? string.Empty :
Marshal.PtrToStringAnsi((IntPtr)formatBuffer)!;
type = GetDriveType(format);
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ internal partial class Interop
internal partial class Kernel32
{
[DllImport(Libraries.Kernel32, EntryPoint = "SetVolumeLabelW", CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
internal static extern bool SetVolumeLabel(string driveLetter, string volumeName);
internal static extern bool SetVolumeLabel(string driveLetter, string? volumeName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public DriveInfo(string driveName) { }
public System.IO.DirectoryInfo RootDirectory { get { throw null; } }
public long TotalFreeSpace { get { throw null; } }
public long TotalSize { get { throw null; } }
[System.Diagnostics.CodeAnalysis.AllowNull]
public string VolumeLabel { get { throw null; } set { } }
public static System.IO.DriveInfo[] GetDrives() { throw null; }
void System.Runtime.Serialization.ISerializable.GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
Expand All @@ -27,8 +28,8 @@ public partial class DriveNotFoundException : System.IO.IOException
{
public DriveNotFoundException() { }
protected DriveNotFoundException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context) { }
public DriveNotFoundException(string message) { }
public DriveNotFoundException(string message, System.Exception innerException) { }
public DriveNotFoundException(string? message) { }
public DriveNotFoundException(string? message, System.Exception? innerException) { }
}
public enum DriveType
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Nullable>enable</Nullable>
<Configurations>netcoreapp-Debug;netcoreapp-Release</Configurations>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<RootNamespace>System.IO.FileSystem.DriveInfo</RootNamespace>
<AssemblyName>System.IO.FileSystem.DriveInfo</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
<Configurations>netcoreapp-Unix-Debug;netcoreapp-Unix-Release;netcoreapp-Windows_NT-Debug;netcoreapp-Windows_NT-Release</Configurations>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Security;

namespace System.IO
Expand Down Expand Up @@ -104,6 +105,7 @@ public long TotalSize
}
}

[AllowNull]
public string VolumeLabel
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Text;

Expand Down Expand Up @@ -121,6 +122,7 @@ public static DriveInfo[] GetDrives()
}

// Null is a valid volume label.
[AllowNull]
public unsafe string VolumeLabel
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public DriveNotFoundException()
HResult = HResults.COR_E_DIRECTORYNOTFOUND;
}

public DriveNotFoundException(string message)
public DriveNotFoundException(string? message)
: base(message)
{
HResult = HResults.COR_E_DIRECTORYNOTFOUND;
}

public DriveNotFoundException(string message, Exception innerException)
public DriveNotFoundException(string? message, Exception? innerException)
: base(message, innerException)
{
HResult = HResults.COR_E_DIRECTORYNOTFOUND;
Expand Down