Skip to content

Commit

Permalink
[Group 2] Enable nullable annotations for `Microsoft.Extensions.FileP…
Browse files Browse the repository at this point in the history
…roviders.Abstractions` (#57405)

* Annotate src

* Annotate ref

* GetFileInfo.subpath is not null

* Update Microsoft.Extensions.FileProviders.Abstractions.cs

* Commit to rerun CI

* Revert "Commit to rerun CI"

This reverts commit 4675f86.

* subpath is non-nullable
  • Loading branch information
maxkoshevoi committed Aug 25, 2021
1 parent d40fbf4 commit b9fc51b
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 7 deletions.
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 partial class NotFoundFileInfo : Microsoft.Extensions.FileProviders.IFile
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 @@ public partial class NullChangeToken : Microsoft.Extensions.Primitives.IChangeTo
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
@@ -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
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
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
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
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
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

0 comments on commit b9fc51b

Please sign in to comment.