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 4] Enable nullable annotations for Microsoft.Extensions.Configuration.FileExtensions #57434

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
2677495
Add net6 to parent projects
maxkoshevoi Aug 15, 2021
3500c3b
Annotate
maxkoshevoi Aug 15, 2021
df01b01
Update FileConfigurationProvider.cs
maxkoshevoi Aug 24, 2021
3083bef
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Aug 24, 2021
d328d7b
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Aug 26, 2021
9878964
DisableImplicitAssemblyReferences
maxkoshevoi Aug 26, 2021
88c4584
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Sep 8, 2021
d03a847
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Oct 6, 2021
bd79d32
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Oct 13, 2021
d85eaa3
Use compaund assigment
maxkoshevoi Oct 13, 2021
fdf9aa2
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Nov 18, 2021
8fa2aa3
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Nov 19, 2021
2ed875d
IFileInfo.Name is nullable
maxkoshevoi Nov 19, 2021
851c34f
DisallowNull
maxkoshevoi Nov 19, 2021
4cdc005
NetCoreAppMinimum
maxkoshevoi Nov 19, 2021
afdfb12
Fix NetCoreAppMinimum build
maxkoshevoi Nov 20, 2021
ff33bcf
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Dec 9, 2021
0801c30
Revert "IFileInfo.Name is nullable"
maxkoshevoi Dec 9, 2021
a576913
NotFoundFileInfo replaces null with ""
maxkoshevoi Dec 9, 2021
a06b504
New default constructor for FileLoadExceptionContext
maxkoshevoi Dec 9, 2021
fe6973d
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Dec 11, 2021
e4f24a2
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Jan 5, 2022
c5e8d9d
Revert "NotFoundFileInfo replaces null with """
maxkoshevoi Jan 5, 2022
146577c
Revert "New default constructor for FileLoadExceptionContext"
maxkoshevoi Jan 5, 2022
c2bef34
Suppress warning
maxkoshevoi Jan 5, 2022
a143589
Merge branch 'main' into mk/43605-Configuration-FileExtensions
maxkoshevoi Jan 7, 2022
5be2593
GetFileProvider non nullable return
maxkoshevoi Jan 7, 2022
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 @@ -8,8 +8,8 @@ namespace Microsoft.Extensions.Configuration
{
public static partial class FileConfigurationExtensions
{
public static System.Action<Microsoft.Extensions.Configuration.FileLoadExceptionContext> GetFileLoadExceptionHandler(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder) { throw null; }
public static Microsoft.Extensions.FileProviders.IFileProvider GetFileProvider(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder) { throw null; }
public static System.Action<Microsoft.Extensions.Configuration.FileLoadExceptionContext>? GetFileLoadExceptionHandler(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder) { throw null; }
public static Microsoft.Extensions.FileProviders.IFileProvider? GetFileProvider(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder) { throw null; }
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
public static Microsoft.Extensions.Configuration.IConfigurationBuilder SetBasePath(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string basePath) { throw null; }
public static Microsoft.Extensions.Configuration.IConfigurationBuilder SetFileLoadExceptionHandler(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.Action<Microsoft.Extensions.Configuration.FileLoadExceptionContext> handler) { throw null; }
halter73 marked this conversation as resolved.
Show resolved Hide resolved
public static Microsoft.Extensions.Configuration.IConfigurationBuilder SetFileProvider(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, Microsoft.Extensions.FileProviders.IFileProvider fileProvider) { throw null; }
Expand All @@ -27,10 +27,10 @@ public override void Load() { }
public abstract partial class FileConfigurationSource : Microsoft.Extensions.Configuration.IConfigurationSource
{
protected FileConfigurationSource() { }
public Microsoft.Extensions.FileProviders.IFileProvider FileProvider { get { throw null; } set { } }
public System.Action<Microsoft.Extensions.Configuration.FileLoadExceptionContext> OnLoadException { get { throw null; } set { } }
public Microsoft.Extensions.FileProviders.IFileProvider? FileProvider { get { throw null; } set { } }
public System.Action<Microsoft.Extensions.Configuration.FileLoadExceptionContext>? OnLoadException { get { throw null; } set { } }
public bool Optional { get { throw null; } set { } }
public string Path { get { throw null; } set { } }
public string? Path { get { throw null; } set { } }
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
public int ReloadDelay { get { throw null; } set { } }
public bool ReloadOnChange { get { throw null; } set { } }
public abstract Microsoft.Extensions.Configuration.IConfigurationProvider Build(Microsoft.Extensions.Configuration.IConfigurationBuilder builder);
Expand All @@ -40,8 +40,8 @@ public void ResolveFileProvider() { }
public partial class FileLoadExceptionContext
{
public FileLoadExceptionContext() { }
public System.Exception Exception { get { throw null; } set { } }
public System.Exception? Exception { get { throw null; } set { } }
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
public bool Ignore { get { throw null; } set { } }
public Microsoft.Extensions.Configuration.FileConfigurationProvider Provider { get { throw null; } set { } }
public Microsoft.Extensions.Configuration.FileConfigurationProvider? Provider { get { throw null; } set { } }
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="Microsoft.Extensions.Configuration.FileExtensions.cs" />
Expand All @@ -9,4 +10,8 @@
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.FileProviders.Abstractions\ref\Microsoft.Extensions.FileProviders.Abstractions.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)Microsoft.Extensions.FileProviders.Physical\ref\Microsoft.Extensions.FileProviders.Physical.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<ProjectReference Include="$(LibrariesProjectRoot)System.Collections\ref\System.Collections.csproj" />
<ProjectReference Include="$(LibrariesProjectRoot)System.Runtime\ref\System.Runtime.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ public static IConfigurationBuilder SetFileProvider(this IConfigurationBuilder b
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param>
/// <returns>The default <see cref="IFileProvider"/>.</returns>
public static IFileProvider GetFileProvider(this IConfigurationBuilder builder)
public static IFileProvider? GetFileProvider(this IConfigurationBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}

if (builder.Properties.TryGetValue(FileProviderKey, out object provider))
if (builder.Properties.TryGetValue(FileProviderKey, out object? provider))
{
return provider as IFileProvider;
}
Expand Down Expand Up @@ -94,14 +94,14 @@ public static IConfigurationBuilder SetFileLoadExceptionHandler(this IConfigurat
/// </summary>
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param>
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns>
public static Action<FileLoadExceptionContext> GetFileLoadExceptionHandler(this IConfigurationBuilder builder)
public static Action<FileLoadExceptionContext>? GetFileLoadExceptionHandler(this IConfigurationBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}

if (builder.Properties.TryGetValue(FileLoadExceptionHandlerKey, out object handler))
if (builder.Properties.TryGetValue(FileLoadExceptionHandlerKey, out object? handler))
{
return handler as Action<FileLoadExceptionContext>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.Extensions.Configuration
/// </summary>
public abstract class FileConfigurationProvider : ConfigurationProvider, IDisposable
{
private readonly IDisposable _changeTokenRegistration;
private readonly IDisposable? _changeTokenRegistration;

/// <summary>
/// Initializes a new instance with the specified source.
Expand All @@ -30,7 +30,7 @@ public FileConfigurationProvider(FileConfigurationSource source)
if (Source.ReloadOnChange && Source.FileProvider != null)
{
_changeTokenRegistration = ChangeToken.OnChange(
() => Source.FileProvider.Watch(Source.Path),
() => Source.FileProvider.Watch(Source.Path!),
() =>
{
Thread.Sleep(Source.ReloadDelay);
Expand All @@ -53,12 +53,12 @@ public override string ToString()

private void Load(bool reload)
{
IFileInfo file = Source.FileProvider?.GetFileInfo(Source.Path);
IFileInfo? file = Source.FileProvider?.GetFileInfo(Source.Path ?? string.Empty);
maxkoshevoi marked this conversation as resolved.
Show resolved Hide resolved
if (file == null || !file.Exists)
{
if (Source.Optional || reload) // Always optional on reload
{
Data = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Data = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
}
else
{
Expand Down Expand Up @@ -100,7 +100,7 @@ static Stream OpenRead(IFileInfo fileInfo)
{
if (reload)
{
Data = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
Data = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase);
}
var exception = new InvalidDataException(SR.Format(SR.Error_FailedToLoad, file.PhysicalPath), ex);
HandleException(ExceptionDispatchInfo.Capture(exception));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ public abstract class FileConfigurationSource : IConfigurationSource
/// <summary>
/// Used to access the contents of the file.
/// </summary>
public IFileProvider FileProvider { get; set; }
public IFileProvider? FileProvider { get; set; }

/// <summary>
/// The path to the file.
/// </summary>
public string Path { get; set; }
public string? Path { get; set; }

/// <summary>
/// Determines if loading the file is optional.
Expand All @@ -41,7 +41,7 @@ public abstract class FileConfigurationSource : IConfigurationSource
/// <summary>
/// Will be called if an uncaught exception occurs in FileConfigurationProvider.Load.
/// </summary>
public Action<FileLoadExceptionContext> OnLoadException { get; set; }
public Action<FileLoadExceptionContext>? OnLoadException { get; set; }

/// <summary>
/// Builds the <see cref="IConfigurationProvider"/> for this source.
Expand All @@ -56,8 +56,8 @@ public abstract class FileConfigurationSource : IConfigurationSource
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param>
public void EnsureDefaults(IConfigurationBuilder builder)
{
FileProvider = FileProvider ?? builder.GetFileProvider();
OnLoadException = OnLoadException ?? builder.GetFileLoadExceptionHandler();
FileProvider ??= builder.GetFileProvider();
OnLoadException ??= builder.GetFileLoadExceptionHandler();
}

/// <summary>
Expand All @@ -70,8 +70,8 @@ public void ResolveFileProvider()
!string.IsNullOrEmpty(Path) &&
System.IO.Path.IsPathRooted(Path))
{
string directory = System.IO.Path.GetDirectoryName(Path);
string pathToFile = System.IO.Path.GetFileName(Path);
string? directory = System.IO.Path.GetDirectoryName(Path);
string? pathToFile = System.IO.Path.GetFileName(Path);
while (!string.IsNullOrEmpty(directory) && !Directory.Exists(directory))
{
pathToFile = System.IO.Path.Combine(System.IO.Path.GetFileName(directory), pathToFile);
Expand All @@ -84,6 +84,5 @@ public void ResolveFileProvider()
}
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public class FileLoadExceptionContext
/// <summary>
/// The <see cref="FileConfigurationProvider"/> that caused the exception.
/// </summary>
public FileConfigurationProvider Provider { get; set; }
public FileConfigurationProvider? Provider { get; set; }

/// <summary>
/// The exception that occurred in Load.
/// </summary>
public Exception Exception { get; set; }
public Exception? Exception { get; set; }

/// <summary>
/// If true, the exception will not be rethrown.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<TargetFrameworks>$(NetCoreAppCurrent);netstandard2.0;$(NetFrameworkMinimum)</TargetFrameworks>
<Nullable>enable</Nullable>
<EnableDefaultItems>true</EnableDefaultItems>
<!-- Use targeting pack references instead of granular ones in the project file. -->
<DisableImplicitAssemblyReferences>false</DisableImplicitAssemblyReferences>
<PackageDescription>Extension methods for configuring file-based configuration providers for Microsoft.Extensions.Configuration.</PackageDescription>
</PropertyGroup>

Expand Down