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

[Group 2] Enable nullable annotations for Microsoft.Extensions.FileProviders.Abstractions #57405

Merged
merged 9 commits into from
Aug 25, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public partial interface IFileInfo
System.DateTimeOffset LastModified { get; }
long Length { get; }
string Name { get; }
string PhysicalPath { get; }
string? PhysicalPath { get; }
System.IO.Stream CreateReadStream();
}
public partial interface IFileProvider
Expand All @@ -42,7 +42,8 @@ public NotFoundFileInfo(string name) { }
public System.DateTimeOffset LastModified { get { throw null; } }
public long Length { get { throw null; } }
public string Name { get { throw null; } }
public string PhysicalPath { get { throw null; } }
public string? PhysicalPath { get { throw null; } }
[System.Diagnostics.CodeAnalysis.DoesNotReturn]
public System.IO.Stream CreateReadStream() { throw null; }
}
public partial class NullChangeToken : Microsoft.Extensions.Primitives.IChangeToken
Expand All @@ -51,7 +52,7 @@ internal NullChangeToken() { }
public bool ActiveChangeCallbacks { get { throw null; } }
public bool HasChanged { get { throw null; } }
public static Microsoft.Extensions.FileProviders.NullChangeToken Singleton { get { throw null; } }
public System.IDisposable RegisterChangeCallback(System.Action<object> callback, object state) { throw null; }
public System.IDisposable RegisterChangeCallback(System.Action<object?> callback, object? state) { throw null; }
}
public partial class NullFileProvider : Microsoft.Extensions.FileProviders.IFileProvider
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Microsoft.Extensions.FileProviders.Abstractions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface IFileInfo
/// <summary>
/// The path to the file, including the file name. Return null if the file is not directly accessible.
/// </summary>
string PhysicalPath { get; }
string? PhysicalPath { get; }

/// <summary>
/// The name of the file or directory, not including any path.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<RootNamespace>Microsoft.Extensions.FileProviders</RootNamespace>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;net461</TargetFrameworks>
<Nullable>enable</Nullable>
<EnableDefaultItems>true</EnableDefaultItems>
<PackageDescription>Abstractions of files and directories.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class NotFoundDirectoryContents : IDirectoryContents
/// <summary>
/// A shared instance of <see cref="NotFoundDirectoryContents"/>
/// </summary>
public static NotFoundDirectoryContents Singleton { get; } = new NotFoundDirectoryContents();
public static NotFoundDirectoryContents Singleton { get; } = new();

/// <summary>
/// Always false.
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.

using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace Microsoft.Extensions.FileProviders
Expand Down Expand Up @@ -46,13 +47,14 @@ public NotFoundFileInfo(string name)
/// <summary>
/// Always null.
/// </summary>
public string PhysicalPath => null;
public string? PhysicalPath => null;

/// <summary>
/// Always throws. A stream cannot be created for non-existing file.
/// </summary>
/// <exception cref="FileNotFoundException">Always thrown.</exception>
/// <returns>Does not return</returns>
[DoesNotReturn]
public Stream CreateReadStream()
{
throw new FileNotFoundException(SR.Format(SR.FileNotExists, Name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private NullChangeToken()
/// <param name="callback">This parameter is ignored</param>
/// <param name="state">This parameter is ignored</param>
/// <returns>A disposable object that noops on dispose.</returns>
public IDisposable RegisterChangeCallback(Action<object> callback, object state)
public IDisposable RegisterChangeCallback(Action<object?> callback, object? state)
{
return EmptyDisposable.Instance;
}
Expand Down