Skip to content
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 @@ -11,7 +11,7 @@ namespace Microsoft.Extensions.Configuration.KeyPerFile
/// </summary>
public class KeyPerFileConfigurationProvider : ConfigurationProvider, IDisposable
{
private readonly IDisposable _changeTokenRegistration;
private readonly IDisposable? _changeTokenRegistration;

KeyPerFileConfigurationSource Source { get; set; }

Expand Down Expand Up @@ -106,7 +106,7 @@ private string GetDirectoryName()
/// <summary>
/// Generates a string representing this provider name and relevant details.
/// </summary>
/// <returns> The configuration name. </returns>
/// <returns>The configuration name.</returns>
public override string ToString()
=> $"{GetType().Name} for files in '{GetDirectoryName()}' ({(Source.Optional ? "Optional" : "Required")})";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public KeyPerFileConfigurationSource()
/// <summary>
/// The FileProvider whos root "/" directory files will be used as configuration data.
/// </summary>
public IFileProvider FileProvider { get; set; }
public IFileProvider? FileProvider { get; set; }

/// <summary>
/// Files that start with this prefix will be excluded.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>Configuration provider that uses files in a directory for Microsoft.Extensions.Configuration.</Description>
Expand All @@ -8,6 +8,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>configuration</PackageTags>
<NoWarn>$(NoWarn);PKG0001</NoWarn>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
26 changes: 13 additions & 13 deletions src/Configuration.KeyPerFile/src/PublicAPI.Shipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.Relo
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.ReloadOnChange.set -> void
Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions
override Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationProvider.Load() -> void
~Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationProvider.KeyPerFileConfigurationProvider(Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource source) -> void
~Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.Build(Microsoft.Extensions.Configuration.IConfigurationBuilder builder) -> Microsoft.Extensions.Configuration.IConfigurationProvider
~Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.FileProvider.get -> Microsoft.Extensions.FileProviders.IFileProvider
~Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.FileProvider.set -> void
~Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.IgnoreCondition.get -> System.Func<string, bool>
~Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.IgnoreCondition.set -> void
~Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.IgnorePrefix.get -> string
~Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.IgnorePrefix.set -> void
~override Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationProvider.ToString() -> string
~static Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, System.Action<Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource> configureSource) -> Microsoft.Extensions.Configuration.IConfigurationBuilder
~static Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string directoryPath) -> Microsoft.Extensions.Configuration.IConfigurationBuilder
~static Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string directoryPath, bool optional) -> Microsoft.Extensions.Configuration.IConfigurationBuilder
~static Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder builder, string directoryPath, bool optional, bool reloadOnChange) -> Microsoft.Extensions.Configuration.IConfigurationBuilder
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationProvider.KeyPerFileConfigurationProvider(Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource! source) -> void
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.Build(Microsoft.Extensions.Configuration.IConfigurationBuilder! builder) -> Microsoft.Extensions.Configuration.IConfigurationProvider!
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.FileProvider.get -> Microsoft.Extensions.FileProviders.IFileProvider?
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.FileProvider.set -> void
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.IgnoreCondition.get -> System.Func<string!, bool>!
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.IgnoreCondition.set -> void
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.IgnorePrefix.get -> string!
Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource.IgnorePrefix.set -> void
override Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationProvider.ToString() -> string!
static Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder! builder, System.Action<Microsoft.Extensions.Configuration.KeyPerFile.KeyPerFileConfigurationSource!>! configureSource) -> Microsoft.Extensions.Configuration.IConfigurationBuilder!
static Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder! builder, string! directoryPath) -> Microsoft.Extensions.Configuration.IConfigurationBuilder!
static Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder! builder, string! directoryPath, bool optional) -> Microsoft.Extensions.Configuration.IConfigurationBuilder!
static Microsoft.Extensions.Configuration.KeyPerFileConfigurationBuilderExtensions.AddKeyPerFile(this Microsoft.Extensions.Configuration.IConfigurationBuilder! builder, string! directoryPath, bool optional, bool reloadOnChange) -> Microsoft.Extensions.Configuration.IConfigurationBuilder!
2 changes: 1 addition & 1 deletion src/FileProviders/Embedded/src/EmbeddedFileProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public EmbeddedFileProvider(Assembly assembly)
/// </summary>
/// <param name="assembly">The assembly that contains the embedded resources.</param>
/// <param name="baseNamespace">The base namespace that contains the embedded resources.</param>
public EmbeddedFileProvider(Assembly assembly, string baseNamespace)
public EmbeddedFileProvider(Assembly assembly, string? baseNamespace)
{
if (assembly == null)
{
Expand Down
23 changes: 16 additions & 7 deletions src/FileProviders/Embedded/src/EmbeddedResourceFileInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -50,10 +50,8 @@ public long Length
{
if (!_length.HasValue)
{
using (var stream = _assembly.GetManifestResourceStream(_resourcePath))
{
_length = stream.Length;
}
using var stream = GetManifestResourceStream();
_length = stream.Length;
}
return _length.Value;
}
Expand All @@ -62,7 +60,7 @@ public long Length
/// <summary>
/// Always null.
/// </summary>
public string PhysicalPath => null;
public string? PhysicalPath => null;

/// <summary>
/// The name of embedded file
Expand All @@ -82,13 +80,24 @@ public long Length
/// <inheritdoc />
public Stream CreateReadStream()
{
var stream = _assembly.GetManifestResourceStream(_resourcePath);
var stream = GetManifestResourceStream();
if (!_length.HasValue)
{
_length = stream.Length;
}

return stream;
}

private Stream GetManifestResourceStream()
{
var stream = _assembly.GetManifestResourceStream(_resourcePath);
if (stream == null)
{
throw new InvalidOperationException($"Couldn't get resource at '{_resourcePath}'.");
}

return stream;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -28,7 +28,7 @@ internal EmbeddedFilesManifest(ManifestDirectory rootDirectory)
_rootDirectory = rootDirectory;
}

internal ManifestEntry ResolveEntry(string path)
internal ManifestEntry? ResolveEntry(string path)
{
if (string.IsNullOrEmpty(path) || HasInvalidPathChars(path))
{
Expand Down
4 changes: 2 additions & 2 deletions src/FileProviders/Embedded/src/Manifest/ManifestDirectory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -31,7 +31,7 @@ public override ManifestEntry Traverse(StringSegment segment)

if (segment.Equals("..", StringComparison.Ordinal))
{
return Parent;
return Parent ?? UnknownPath;
}

foreach (var child in Children)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand All @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.FileProviders.Embedded.Manifest
internal class ManifestDirectoryContents : IDirectoryContents
{
private readonly DateTimeOffset _lastModified;
private IFileInfo[] _entries;
private IFileInfo[]? _entries;

public ManifestDirectoryContents(Assembly assembly, ManifestDirectory directory, DateTimeOffset lastModified)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand All @@ -23,9 +23,9 @@ public ManifestDirectoryInfo(ManifestDirectory directory, DateTimeOffset lastMod

public long Length => -1;

public string PhysicalPath => null;
public string? PhysicalPath => null;

public string Name => Directory.Name;
public string? Name => Directory.Name;

public DateTimeOffset LastModified { get; }

Expand Down
4 changes: 2 additions & 2 deletions src/FileProviders/Embedded/src/Manifest/ManifestEntry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand All @@ -13,7 +13,7 @@ public ManifestEntry(string name)
Name = name;
}

public ManifestEntry Parent { get; private set; }
public ManifestEntry? Parent { get; private set; }

public string Name { get; }

Expand Down
25 changes: 17 additions & 8 deletions src/FileProviders/Embedded/src/Manifest/ManifestFileInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -36,9 +36,9 @@ public ManifestFileInfo(Assembly assembly, ManifestFile file, DateTimeOffset las

public long Length => EnsureLength();

public string PhysicalPath => null;
public string? PhysicalPath => null;

public string Name => ManifestFile.Name;
public string? Name => ManifestFile.Name;

public DateTimeOffset LastModified { get; }

Expand All @@ -48,24 +48,33 @@ private long EnsureLength()
{
if (_length == null)
{
using (var stream = Assembly.GetManifestResourceStream(ManifestFile.ResourcePath))
{
_length = stream.Length;
}
using var stream = GetManifestResourceStream();
_length = stream.Length;
}

return _length.Value;
}

public Stream CreateReadStream()
{
var stream = Assembly.GetManifestResourceStream(ManifestFile.ResourcePath);
var stream = GetManifestResourceStream();
if (!_length.HasValue)
{
_length = stream.Length;
}

return stream;
}

private Stream GetManifestResourceStream()
{
var stream = Assembly.GetManifestResourceStream(ManifestFile.ResourcePath);
if (stream == null)
{
throw new InvalidOperationException($"Couldn't get resource at '{ManifestFile.ResourcePath}'.");
}

return stream;
}
}
}
4 changes: 2 additions & 2 deletions src/FileProviders/Embedded/src/Manifest/ManifestParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand Down Expand Up @@ -146,7 +146,7 @@ private static string EnsureText(XElement element)
if (element.Elements().Count() == 0 &&
!element.IsEmpty &&
element.Nodes().Count() == 1 &&
element.FirstNode.NodeType == XmlNodeType.Text)
element.FirstNode?.NodeType == XmlNodeType.Text)
{
return element.Value;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

namespace Microsoft.Extensions.FileProviders.Embedded.Manifest
{
internal class ManifestRootDirectory : ManifestDirectory
{
public ManifestRootDirectory(ManifestEntry[] children)
: base(name: null, children: children)
: base(name: string.Empty, children: children)
{
SetParent(ManifestSinkDirectory.Instance);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
Expand All @@ -9,7 +9,7 @@ namespace Microsoft.Extensions.FileProviders.Embedded.Manifest
internal class ManifestSinkDirectory : ManifestDirectory
{
private ManifestSinkDirectory()
: base(name: null, children: Array.Empty<ManifestEntry>())
: base(name: string.Empty, children: Array.Empty<ManifestEntry>())
{
SetParent(this);
Children = new[] { this };
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<RootNamespace>Microsoft.Extensions.FileProviders</RootNamespace>
Expand All @@ -11,6 +11,7 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageTags>files;filesystem</PackageTags>
<NoPackageAnalysis>true</NoPackageAnalysis>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
Expand Down
Loading