Skip to content

Commit 25c824c

Browse files
committed
Refactoring
1 parent d2026ee commit 25c824c

File tree

4 files changed

+14
-18
lines changed

4 files changed

+14
-18
lines changed

src/My.Extensions.Localization.Json/Internal/JsonResourceManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ namespace My.Extensions.Localization.Json.Internal;
99

1010
public class JsonResourceManager
1111
{
12-
private readonly List<JsonFileWatcher> _jsonFileWatchers = new();
12+
private readonly List<JsonFileWatcher> _jsonFileWatchers = [];
1313
private readonly ConcurrentDictionary<string, ConcurrentDictionary<string, string>> _resourcesCache = new();
1414
private readonly ConcurrentDictionary<string, HashSet<string>> _loadedFilesCache = new();
1515

1616
public JsonResourceManager(string resourcesPath, string resourceName = null)
17-
: this(new[] { resourcesPath }, fallBackToParentUICultures: true, resourceName)
17+
: this([resourcesPath], fallBackToParentUICultures: true, resourceName)
1818
{
1919
}
2020

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
using System;
2-
using Microsoft.Extensions.Localization;
1+
using Microsoft.Extensions.Localization;
32

43
namespace My.Extensions.Localization.Json;
54

65
public class JsonLocalizationOptions : LocalizationOptions
76
{
87
public ResourcesType ResourcesType { get; set; } = ResourcesType.TypeBased;
98

10-
public new string[] ResourcesPath { get; set; } = Array.Empty<string>();
9+
public new string[] ResourcesPath { get; set; } = [];
1110
}

src/My.Extensions.Localization.Json/JsonStringLocalizerFactory.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public JsonStringLocalizerFactory(
3737
{
3838
ArgumentNullException.ThrowIfNull(localizationOptions);
3939

40-
_resourcesPaths = localizationOptions.Value.ResourcesPath ?? Array.Empty<string>();
40+
_resourcesPaths = localizationOptions.Value.ResourcesPath ?? [];
4141
_resourcesType = localizationOptions.Value.ResourcesType;
4242
_fallBackToParentUICultures = requestLocalizationOptions?.Value?.FallBackToParentUICultures ?? true;
4343
_loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
@@ -115,12 +115,10 @@ private string[] GetResourcePaths(Assembly assembly)
115115

116116
if (resourceLocationAttribute != null)
117117
{
118-
return new[] { Path.Combine(PathHelpers.GetApplicationRoot(), resourceLocationAttribute.ResourceLocation) };
118+
return [Path.Combine(PathHelpers.GetApplicationRoot(), resourceLocationAttribute.ResourceLocation)];
119119
}
120120

121-
return _resourcesPaths
122-
.Select(p => Path.Combine(PathHelpers.GetApplicationRoot(), p))
123-
.ToArray();
121+
return [.. _resourcesPaths.Select(p => Path.Combine(PathHelpers.GetApplicationRoot(), p))];
124122
}
125123

126124
private static string GetRootNamespace(Assembly assembly)

test/My.Extensions.Localization.Json.Tests/JsonStringLocalizerTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System.Collections.Generic;
2-
using System.Linq;
3-
using System.Threading.Tasks;
4-
using Microsoft.AspNetCore.Builder;
1+
using Microsoft.AspNetCore.Builder;
52
using Microsoft.AspNetCore.Hosting;
63
using Microsoft.AspNetCore.TestHost;
74
using Microsoft.Extensions.DependencyInjection;
@@ -10,6 +7,8 @@
107
using Microsoft.Extensions.Options;
118
using Moq;
129
using My.Extensions.Localization.Json.Tests.Common;
10+
using System.Linq;
11+
using System.Threading.Tasks;
1312
using Xunit;
1413

1514
namespace My.Extensions.Localization.Json.Tests;
@@ -22,7 +21,7 @@ public JsonStringLocalizerTests()
2221
{
2322
var _localizationOptions = new Mock<IOptions<JsonLocalizationOptions>>();
2423
_localizationOptions.Setup(o => o.Value)
25-
.Returns(() => new JsonLocalizationOptions { ResourcesPath = new[] { "Resources" } });
24+
.Returns(() => new JsonLocalizationOptions { ResourcesPath = ["Resources"] });
2625
var localizerFactory = new JsonStringLocalizerFactory(_localizationOptions.Object, NullLoggerFactory.Instance);
2726
var location = "My.Extensions.Localization.Json.Tests";
2827
var basename = $"{location}.Common.{nameof(Test)}";
@@ -135,7 +134,7 @@ public async void CultureBasedResourcesUsesIStringLocalizer()
135134
{
136135
services.AddJsonLocalization(options =>
137136
{
138-
options.ResourcesPath = new[] { "Resources" };
137+
options.ResourcesPath = ["Resources"];
139138
options.ResourcesType = ResourcesType.CultureBased;
140139
});
141140
})
@@ -185,7 +184,7 @@ public void GetTranslation_WithFallBackToParentUICulturesDisabled_DoesNotFallbac
185184
localizationOptions.Setup(o => o.Value)
186185
.Returns(() => new JsonLocalizationOptions
187186
{
188-
ResourcesPath = new[] { "Resources" }
187+
ResourcesPath = ["Resources"]
189188
});
190189

191190
var requestLocalizationOptions = new Mock<IOptions<RequestLocalizationOptions>>();
@@ -224,7 +223,7 @@ public void GetTranslation_WithFallBackToParentUICulturesEnabled_FallsBackToPare
224223
localizationOptions.Setup(o => o.Value)
225224
.Returns(() => new JsonLocalizationOptions
226225
{
227-
ResourcesPath = new[] { "Resources" }
226+
ResourcesPath = ["Resources"]
228227
});
229228

230229
var requestLocalizationOptions = new Mock<IOptions<RequestLocalizationOptions>>();

0 commit comments

Comments
 (0)