Skip to content

Commit 016f849

Browse files
Code cleanup (seal classes, parameter null checking, expression bodies)
1 parent 01bb12f commit 016f849

File tree

8 files changed

+102
-113
lines changed

8 files changed

+102
-113
lines changed

src/Umbraco.StorageProviders.AzureBlob/AzureBlobDirectoryContents.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ namespace Umbraco.StorageProviders.AzureBlob
1212
/// Represents a virtual hierarchy of Azure Blob Storage blobs.
1313
/// </summary>
1414
/// <seealso cref="Microsoft.Extensions.FileProviders.IDirectoryContents" />
15-
public class AzureBlobDirectoryContents : IDirectoryContents
15+
public sealed class AzureBlobDirectoryContents : IDirectoryContents
1616
{
1717
private readonly BlobContainerClient _containerClient;
18-
private readonly IList<BlobHierarchyItem> _items;
18+
private readonly IReadOnlyCollection<BlobHierarchyItem> _items;
1919

2020
/// <inheritdoc />
2121
public bool Exists { get; }
@@ -28,12 +28,12 @@ public class AzureBlobDirectoryContents : IDirectoryContents
2828
/// <exception cref="System.ArgumentNullException">containerClient
2929
/// or
3030
/// items</exception>
31-
public AzureBlobDirectoryContents(BlobContainerClient containerClient, IList<BlobHierarchyItem> items)
31+
public AzureBlobDirectoryContents(BlobContainerClient containerClient, IReadOnlyCollection<BlobHierarchyItem> items)
3232
{
3333
_containerClient = containerClient ?? throw new ArgumentNullException(nameof(containerClient));
3434
_items = items ?? throw new ArgumentNullException(nameof(items));
3535

36-
Exists = _items.Count > 0;
36+
Exists = items.Count > 0;
3737
}
3838

3939
/// <inheritdoc />

src/Umbraco.StorageProviders.AzureBlob/AzureBlobFileProvider.cs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System;
2-
using System.Collections.Generic;
2+
using System.Linq;
33
using System.Net;
44
using Azure;
55
using Azure.Storage.Blobs;
@@ -16,7 +16,7 @@ namespace Umbraco.StorageProviders.AzureBlob
1616
/// Represents a read-only Azure Blob Storage file provider.
1717
/// </summary>
1818
/// <seealso cref="Microsoft.Extensions.FileProviders.IFileProvider" />
19-
public class AzureBlobFileProvider : IFileProvider
19+
public sealed class AzureBlobFileProvider : IFileProvider
2020
{
2121
private readonly BlobContainerClient _containerClient;
2222
private readonly string? _containerRootPath;
@@ -40,10 +40,7 @@ public AzureBlobFileProvider(BlobContainerClient containerClient, string? contai
4040
/// <exception cref="System.ArgumentNullException">options</exception>
4141
public AzureBlobFileProvider(AzureBlobFileSystemOptions options)
4242
{
43-
if (options is null)
44-
{
45-
throw new ArgumentNullException(nameof(options));
46-
}
43+
ArgumentNullException.ThrowIfNull(options);
4744

4845
_containerClient = new BlobContainerClient(options.ConnectionString, options.ContainerName);
4946
_containerRootPath = options.ContainerRootPath?.Trim(Constants.CharArrays.ForwardSlash);
@@ -55,18 +52,11 @@ public IDirectoryContents GetDirectoryContents(string subpath)
5552
var path = GetFullPath(subpath);
5653

5754
// Get all blobs and iterate to fetch all pages
58-
var blobs = new List<BlobHierarchyItem>();
59-
foreach (var item in _containerClient.GetBlobsByHierarchy(delimiter: "/", prefix: path))
60-
{
61-
blobs.Add(item);
62-
}
63-
64-
if (blobs.Count == 0)
65-
{
66-
return NotFoundDirectoryContents.Singleton;
67-
}
55+
var blobs = _containerClient.GetBlobsByHierarchy(delimiter: "/", prefix: path).ToList();
6856

69-
return new AzureBlobDirectoryContents(_containerClient, blobs);
57+
return blobs.Count == 0
58+
? NotFoundDirectoryContents.Singleton
59+
: new AzureBlobDirectoryContents(_containerClient, blobs);
7060
}
7161

7262
/// <inheritdoc />

src/Umbraco.StorageProviders.AzureBlob/AzureBlobItemInfo.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Umbraco.StorageProviders.AzureBlob
1010
/// Represents an Azure Blob Storage blob item.
1111
/// </summary>
1212
/// <seealso cref="Microsoft.Extensions.FileProviders.IFileInfo" />
13-
public class AzureBlobItemInfo : IFileInfo
13+
public sealed class AzureBlobItemInfo : IFileInfo
1414
{
1515
private readonly BlobClient _blobClient;
1616

@@ -37,7 +37,7 @@ public class AzureBlobItemInfo : IFileInfo
3737
/// </summary>
3838
/// <param name="blobClient">The blob client.</param>
3939
/// <exception cref="System.ArgumentNullException">blobClient</exception>
40-
protected AzureBlobItemInfo(BlobClient blobClient)
40+
private AzureBlobItemInfo(BlobClient blobClient)
4141
{
4242
_blobClient = blobClient ?? throw new ArgumentNullException(nameof(blobClient));
4343

@@ -53,10 +53,7 @@ protected AzureBlobItemInfo(BlobClient blobClient)
5353
public AzureBlobItemInfo(BlobClient blobClient, BlobProperties properties)
5454
: this(blobClient)
5555
{
56-
if (properties == null)
57-
{
58-
throw new ArgumentNullException(nameof(properties));
59-
}
56+
ArgumentNullException.ThrowIfNull(properties);
6057

6158
LastModified = properties.LastModified;
6259
Length = properties.ContentLength;
@@ -71,10 +68,7 @@ public AzureBlobItemInfo(BlobClient blobClient, BlobProperties properties)
7168
public AzureBlobItemInfo(BlobClient blobClient, BlobItemProperties properties)
7269
: this(blobClient)
7370
{
74-
if (properties == null)
75-
{
76-
throw new ArgumentNullException(nameof(properties));
77-
}
71+
ArgumentNullException.ThrowIfNull(properties);
7872

7973
LastModified = properties.LastModified.GetValueOrDefault();
8074
Length = properties.ContentLength.GetValueOrDefault(-1);

src/Umbraco.StorageProviders.AzureBlob/AzureBlobPrefixInfo.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Umbraco.StorageProviders.AzureBlob
88
/// Represents an Azure Blob Storage prefix.
99
/// </summary>
1010
/// <seealso cref="Microsoft.Extensions.FileProviders.IFileInfo" />
11-
public class AzureBlobPrefixInfo : IFileInfo
11+
public sealed class AzureBlobPrefixInfo : IFileInfo
1212
{
1313
/// <inheritdoc />
1414
public bool Exists => true;
@@ -34,10 +34,7 @@ public class AzureBlobPrefixInfo : IFileInfo
3434
/// <param name="prefix">The prefix.</param>
3535
public AzureBlobPrefixInfo(string prefix)
3636
{
37-
if (prefix == null)
38-
{
39-
throw new ArgumentNullException(nameof(prefix));
40-
}
37+
ArgumentNullException.ThrowIfNull(prefix);
4138

4239
Name = ParseName(prefix);
4340
}

0 commit comments

Comments
 (0)