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,14 +17,14 @@ 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
{
Microsoft.Extensions.FileProviders.IDirectoryContents GetDirectoryContents(string subpath);
Microsoft.Extensions.FileProviders.IDirectoryContents GetDirectoryContents(string? subpath);
Microsoft.Extensions.FileProviders.IFileInfo GetFileInfo(string subpath);
Microsoft.Extensions.Primitives.IChangeToken Watch(string filter);
Microsoft.Extensions.Primitives.IChangeToken Watch(string? filter);
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
}
public partial class NotFoundDirectoryContents : Microsoft.Extensions.FileProviders.IDirectoryContents, System.Collections.Generic.IEnumerable<Microsoft.Extensions.FileProviders.IFileInfo>, System.Collections.IEnumerable
{
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,13 +52,13 @@ 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
{
public NullFileProvider() { }
public Microsoft.Extensions.FileProviders.IDirectoryContents GetDirectoryContents(string subpath) { throw null; }
public Microsoft.Extensions.FileProviders.IDirectoryContents GetDirectoryContents(string? subpath) { throw null; }
public Microsoft.Extensions.FileProviders.IFileInfo GetFileInfo(string subpath) { throw null; }
public Microsoft.Extensions.Primitives.IChangeToken Watch(string filter) { throw null; }
public Microsoft.Extensions.Primitives.IChangeToken Watch(string? filter) { throw null; }
}
}
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 @@ -22,13 +22,13 @@ public interface IFileProvider
/// </summary>
/// <param name="subpath">Relative path that identifies the directory.</param>
/// <returns>Returns the contents of the directory.</returns>
IDirectoryContents GetDirectoryContents(string subpath);
IDirectoryContents GetDirectoryContents(string? subpath);

/// <summary>
/// Creates a <see cref="IChangeToken"/> for the specified <paramref name="filter"/>.
/// </summary>
/// <param name="filter">Filter string used to determine what files or folders to monitor. Example: **/*.cs, *.*, subFolder/**/*.cshtml.</param>
/// <returns>An <see cref="IChangeToken"/> that is notified when a file matching <paramref name="filter"/> is added, modified or deleted.</returns>
IChangeToken Watch(string filter);
IChangeToken Watch(string? filter);
}
}
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class NullFileProvider : IFileProvider
/// </summary>
/// <param name="subpath">A path under the root directory. This parameter is ignored.</param>
/// <returns>A <see cref="IDirectoryContents"/> that does not exist and does not contain any contents.</returns>
public IDirectoryContents GetDirectoryContents(string subpath) => NotFoundDirectoryContents.Singleton;
public IDirectoryContents GetDirectoryContents(string? subpath) => NotFoundDirectoryContents.Singleton;

/// <summary>
/// Locate a non-existent file.
Expand All @@ -29,6 +29,6 @@ public class NullFileProvider : IFileProvider
/// </summary>
/// <param name="filter">Filter string used to determine what files or folders to monitor. This parameter is ignored.</param>
/// <returns>A <see cref="IChangeToken"/> that does not register callbacks.</returns>
public IChangeToken Watch(string filter) => NullChangeToken.Singleton;
public IChangeToken Watch(string? filter) => NullChangeToken.Singleton;
}
}