Skip to content

Commit

Permalink
refactor: 撤销更改
Browse files Browse the repository at this point in the history
  • Loading branch information
ArgoZhang committed Jan 4, 2025
1 parent 05b0c60 commit dd78b6e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal static class CacheManagerExtensions
/// <param name="typeName"></param>
/// <param name="options"></param>
/// <returns></returns>
public static FrozenSet<LocalizedString> GetLocalizedStrings(this ICacheManager cache, string typeName, JsonLocalizationOptions options)
public static IEnumerable<LocalizedString> GetLocalizedStrings(this ICacheManager cache, string typeName, JsonLocalizationOptions options)
{
var key = $"Snippet-{CultureInfo.CurrentUICulture.Name}-{nameof(GetLocalizedStrings)}-{typeName}";
return cache.GetOrCreate(key, entry =>
Expand Down
10 changes: 1 addition & 9 deletions src/BootstrapBlazor/Localization/Json/JsonStringLocalizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
using System.Reflection;
using System.Resources;

#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif

namespace BootstrapBlazor.Components;

/// <summary>
Expand Down Expand Up @@ -101,11 +97,7 @@ public override LocalizedString this[string name]
}
}

#if NET8_0_OR_GREATER
private string? GetValueFromCache(FrozenSet<LocalizedString>? localizerStrings, string name)
#else
private string? GetValueFromCache(HashSet<LocalizedString>? localizerStrings, string name)
#endif
private string? GetValueFromCache(IEnumerable<LocalizedString>? localizerStrings, string name)
{
string? ret = null;
var cultureName = CultureInfo.CurrentUICulture.Name;
Expand Down
12 changes: 2 additions & 10 deletions src/BootstrapBlazor/Services/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ private static JsonLocalizationOptions GetJsonLocalizationOption()
/// </summary>
/// <param name="assembly"></param>
/// <param name="typeName"></param>
#if NET8_0_OR_GREATER
public static FrozenSet<LocalizedString>? GetAllStringsByTypeName(Assembly assembly, string typeName)
#else
public static HashSet<LocalizedString>? GetAllStringsByTypeName(Assembly assembly, string typeName)
#endif
public static IEnumerable<LocalizedString>? GetAllStringsByTypeName(Assembly assembly, string typeName)
=> GetJsonStringByTypeName(GetJsonLocalizationOption(), assembly, typeName, CultureInfo.CurrentUICulture.Name);

/// <summary>
Expand All @@ -226,11 +222,7 @@ private static JsonLocalizationOptions GetJsonLocalizationOption()
/// <param name="cultureName">cultureName 未空时使用 CultureInfo.CurrentUICulture.Name</param>
/// <param name="forceLoad">默认 false 使用缓存值 设置 true 时内部强制重新加载</param>
/// <returns></returns>
#if NET8_0_OR_GREATER
public static FrozenSet<LocalizedString>? GetJsonStringByTypeName(JsonLocalizationOptions option, Assembly assembly, string typeName, string? cultureName = null, bool forceLoad = false)
#else
public static HashSet<LocalizedString>? GetJsonStringByTypeName(JsonLocalizationOptions option, Assembly assembly, string typeName, string? cultureName = null, bool forceLoad = false)
#endif
public static IEnumerable<LocalizedString>? GetJsonStringByTypeName(JsonLocalizationOptions option, Assembly assembly, string typeName, string? cultureName = null, bool forceLoad = false)
{
if (assembly.IsDynamic)
{
Expand Down
10 changes: 1 addition & 9 deletions src/BootstrapBlazor/Utils/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
using System.Linq.Expressions;
using System.Reflection;

#if NET8_0_OR_GREATER
using System.Collections.Frozen;
#endif

namespace BootstrapBlazor.Components;

/// <summary>
Expand Down Expand Up @@ -160,11 +156,7 @@ public static class Utility
/// <param name="typeName">类名称</param>
/// <param name="cultureName">cultureName 未空时使用 CultureInfo.CurrentUICulture.Name</param>
/// <param name="forceLoad">默认 false 使用缓存值 设置 true 时内部强制重新加载</param>
#if NET8_0_OR_GREATER
public static FrozenSet<LocalizedString> GetJsonStringByTypeName(JsonLocalizationOptions option, Assembly assembly, string typeName, string? cultureName = null, bool forceLoad = false) => CacheManager.GetJsonStringByTypeName(option, assembly, typeName, cultureName, forceLoad) ?? FrozenSet<LocalizedString>.Empty;
#else
public static HashSet<LocalizedString> GetJsonStringByTypeName(JsonLocalizationOptions option, Assembly assembly, string typeName, string? cultureName = null, bool forceLoad = false) => CacheManager.GetJsonStringByTypeName(option, assembly, typeName, cultureName, forceLoad) ?? new HashSet<LocalizedString>();
#endif
public static IEnumerable<LocalizedString> GetJsonStringByTypeName(JsonLocalizationOptions option, Assembly assembly, string typeName, string? cultureName = null, bool forceLoad = false) => CacheManager.GetJsonStringByTypeName(option, assembly, typeName, cultureName, forceLoad) ?? [];

/// <summary>
/// 通过指定程序集与类型获得 IStringLocalizer 实例
Expand Down

0 comments on commit dd78b6e

Please sign in to comment.