@@ -210,12 +210,6 @@ private static JsonLocalizationOptions GetJsonLocalizationOption()
210210 public static IEnumerable < LocalizedString > ? GetAllStringsByTypeName ( Assembly assembly , string typeName )
211211 => GetJsonStringByTypeName ( GetJsonLocalizationOption ( ) , assembly , typeName , CultureInfo . CurrentUICulture . Name ) ;
212212
213- #if NET9_0_OR_GREATER
214- private static readonly Lock _locker = new ( ) ;
215- #else
216- private static readonly object _locker = new ( ) ;
217- #endif
218-
219213 /// <summary>
220214 /// 通过指定程序集获取所有本地化信息键值集合
221215 /// </summary>
@@ -240,27 +234,24 @@ private static JsonLocalizationOptions GetJsonLocalizationOption()
240234 Instance . Cache . Remove ( key ) ;
241235 }
242236
243- lock ( _locker )
237+ localizedItems = Instance . GetOrCreate ( key , _ =>
244238 {
245- localizedItems = Instance . GetOrCreate ( key , _ =>
239+ var sections = option . GetJsonStringFromAssembly ( assembly , cultureName ) ;
240+ var items = sections . SelectMany ( section => section . GetChildren ( ) . Select ( kv =>
246241 {
247- var sections = option . GetJsonStringFromAssembly ( assembly , cultureName ) ;
248- var items = sections . SelectMany ( section => section . GetChildren ( ) . Select ( kv =>
242+ var value = kv . Value ;
243+ if ( value == null && option . UseKeyWhenValueIsNull == true )
249244 {
250- var value = kv . Value ;
251- if ( value == null && option . UseKeyWhenValueIsNull == true )
252- {
253- value = kv . Key ;
254- }
255- return new LocalizedString ( kv . Key , value ?? "" , false , section . Key ) ;
256- } ) ) ;
245+ value = kv . Key ;
246+ }
247+ return new LocalizedString ( kv . Key , value ?? "" , false , section . Key ) ;
248+ } ) ) ;
257249#if NET8_0_OR_GREATER
258- return items . ToFrozenSet ( ) ;
250+ return items . ToFrozenSet ( ) ;
259251#else
260- return items . ToHashSet ( ) ;
252+ return items . ToHashSet ( ) ;
261253#endif
262- } ) ;
263- }
254+ } ) ;
264255 return localizedItems . Where ( item => item . SearchedLocation ! . Equals ( typeName , StringComparison . OrdinalIgnoreCase ) ) ;
265256 }
266257
0 commit comments