@@ -10,41 +10,35 @@ namespace BootstrapBlazor.Components;
1010
1111class DefaultRegionService : IRegionService
1212{
13- private static readonly ConcurrentDictionary < string , HashSet < string > > _citiesCache = new ( ) ;
14- private static readonly ConcurrentDictionary < string , HashSet < CountyItem > > _countiesCache = new ( ) ;
15- private static readonly ConcurrentDictionary < string , HashSet < string > > _detailCache = new ( ) ;
13+ private static readonly ConcurrentDictionary < string , HashSet < string > > CitiesCache = new ( ) ;
14+ private static readonly ConcurrentDictionary < string , HashSet < CountyItem > > CountiesCache = new ( ) ;
15+ private static readonly ConcurrentDictionary < string , HashSet < string > > DetailCache = new ( ) ;
1616
17- private static bool _initialized = false ;
17+ private static bool _initialized ;
1818
1919#if NET9_0_OR_GREATER
20- private static readonly Lock _lock = new ( ) ;
20+ private static readonly Lock Lock = new ( ) ;
2121#else
22- private static readonly object _lock = new ( ) ;
23- #endif
24-
25- #if NET9_0_OR_GREATER
26- private static readonly Lock _lockDetail = new ( ) ;
27- #else
28- private static readonly object _lockDetail = new ( ) ;
22+ private static readonly object Lock = new ( ) ;
2923#endif
3024
3125 public HashSet < string > GetProvinces ( ) => Provinces ;
3226
3327 public HashSet < string > GetCities ( string province )
3428 {
3529 LoadCityData ( ) ;
36- return _citiesCache . TryGetValue ( province , out var cities ) ? cities : [ ] ;
30+ return CitiesCache . TryGetValue ( province , out var cities ) ? cities : [ ] ;
3731 }
3832
3933 public HashSet < CountyItem > GetCounties ( string city )
4034 {
4135 LoadCityData ( ) ;
42- return _countiesCache . TryGetValue ( city , out var counties ) ? counties : [ ] ;
36+ return CountiesCache . TryGetValue ( city , out var counties ) ? counties : [ ] ;
4337 }
4438
4539 public HashSet < string > GetDetails ( string countyCode )
4640 {
47- return _detailCache . GetOrAdd ( countyCode , LoadDetailData ) ;
41+ return DetailCache . GetOrAdd ( countyCode , LoadDetailData ) ;
4842 }
4943
5044 private static HashSet < string > LoadDetailData ( string countyCode )
@@ -71,7 +65,7 @@ private static void LoadCityData()
7165 {
7266 if ( ! _initialized )
7367 {
74- lock ( _lock )
68+ lock ( Lock )
7569 {
7670 if ( ! _initialized )
7771 {
@@ -117,7 +111,7 @@ private static void LoadDataCore(Stream data)
117111 cities . Add ( value ) ;
118112 }
119113
120- _citiesCache . TryAdd ( value , cities ) ;
114+ CitiesCache . TryAdd ( value , cities ) ;
121115 counties = null ;
122116 continue ;
123117 }
@@ -126,14 +120,14 @@ private static void LoadDataCore(Stream data)
126120 {
127121 cities . Add ( value ) ;
128122 counties = [ ] ;
129- _countiesCache . TryAdd ( value , counties ) ;
123+ CountiesCache . TryAdd ( value , counties ) ;
130124 continue ;
131125 }
132126
133127 if ( counties == null )
134128 {
135129 counties = [ ] ;
136- _countiesCache . TryAdd ( city , counties ) ;
130+ CountiesCache . TryAdd ( city , counties ) ;
137131 }
138132
139133 counties . Add ( new CountyItem ( ) { Name = value , Code = code } ) ;
0 commit comments