@@ -30,7 +30,7 @@ public async Task<Dictionary<string, object>> GetConfigurationAsync()
3030 {
3131 string json = await File . ReadAllTextAsync ( FILE_PATH ) ;
3232 Dictionary < string , object > ? config = JsonSerializer . Deserialize < Dictionary < string , object > > ( json ) ;
33- return config ?? new Dictionary < string , object > ( ) ;
33+ return config ?? [ ] ;
3434 }
3535 catch ( Exception ex )
3636 {
@@ -67,13 +67,11 @@ public async Task<Dictionary<string, object>> GetSectionAsync(string sectionName
6767 {
6868 try
6969 {
70- var config = await GetConfigurationAsync ( ) ;
71- if ( config . ContainsKey ( sectionName ) )
72- {
73- return JsonSerializer . Deserialize < Dictionary < string , object > > (
74- config [ sectionName ] ? . ToString ( ) ?? "{}" ) ?? new Dictionary < string , object > ( ) ;
75- }
76- return new Dictionary < string , object > ( ) ;
70+ Dictionary < string , object > config = await this . GetConfigurationAsync ( ) ;
71+ return config . ContainsKey ( sectionName )
72+ ? JsonSerializer . Deserialize < Dictionary < string , object > > (
73+ config [ sectionName ] ? . ToString ( ) ?? "{}" ) ?? [ ]
74+ : [ ] ;
7775 }
7876 catch ( Exception ex )
7977 {
@@ -91,9 +89,9 @@ public async Task UpdateSectionAsync(string sectionName, Dictionary<string, obje
9189 {
9290 try
9391 {
94- var config = await GetConfigurationAsync ( ) ;
92+ Dictionary < string , object > config = await this . GetConfigurationAsync ( ) ;
9593 config [ sectionName ] = sectionData ;
96- await SaveConfigurationAsync ( config ) ;
94+ await this . SaveConfigurationAsync ( config ) ;
9795 this . _logger . LogInformation ( "Section {SectionName} updated successfully" , sectionName ) ;
9896 }
9997 catch ( Exception ex )
@@ -114,12 +112,8 @@ public async Task UpdateSectionAsync(string sectionName, Dictionary<string, obje
114112 {
115113 try
116114 {
117- var section = await GetSectionAsync ( sectionName ) ;
118- if ( section . ContainsKey ( key ) )
119- {
120- return JsonSerializer . Deserialize < T > ( section [ key ] ? . ToString ( ) ?? "null" ) ;
121- }
122- return default ;
115+ Dictionary < string , object > section = await this . GetSectionAsync ( sectionName ) ;
116+ return section . ContainsKey ( key ) ? JsonSerializer . Deserialize < T > ( section [ key ] ? . ToString ( ) ?? "null" ) : default ;
123117 }
124118 catch ( Exception ex )
125119 {
@@ -138,7 +132,7 @@ public async Task SetValueAsync(string sectionName, string key, object value)
138132 {
139133 try
140134 {
141- var config = await GetConfigurationAsync ( ) ;
135+ Dictionary < string , object > config = await this . GetConfigurationAsync ( ) ;
142136
143137 // Ensure section exists
144138 if ( ! config . ContainsKey ( sectionName ) )
@@ -147,16 +141,16 @@ public async Task SetValueAsync(string sectionName, string key, object value)
147141 }
148142
149143 // Get section
150- var section = JsonSerializer . Deserialize < Dictionary < string , object > > (
151- config [ sectionName ] ? . ToString ( ) ?? "{}" ) ?? new Dictionary < string , object > ( ) ;
144+ Dictionary < string , object > section = JsonSerializer . Deserialize < Dictionary < string , object > > (
145+ config [ sectionName ] ? . ToString ( ) ?? "{}" ) ?? [ ] ;
152146
153147 // Update value
154148 section [ key ] = value ;
155149
156150 // Save back to config
157151 config [ sectionName ] = section ;
158152
159- await SaveConfigurationAsync ( config ) ;
153+ await this . SaveConfigurationAsync ( config ) ;
160154 this . _logger . LogInformation ( "Value for {SectionName}.{Key} updated successfully" , sectionName , key ) ;
161155 }
162156 catch ( Exception ex )
@@ -176,21 +170,22 @@ public async Task<bool> RemoveKeyAsync(string sectionName, string key)
176170 {
177171 try
178172 {
179- var config = await GetConfigurationAsync ( ) ;
173+ Dictionary < string , object > config = await this . GetConfigurationAsync ( ) ;
180174 if ( config . ContainsKey ( sectionName ) )
181175 {
182- var section = JsonSerializer . Deserialize < Dictionary < string , object > > (
183- config [ sectionName ] ? . ToString ( ) ?? "{}" ) ?? new Dictionary < string , object > ( ) ;
176+ Dictionary < string , object > section = JsonSerializer . Deserialize < Dictionary < string , object > > (
177+ config [ sectionName ] ? . ToString ( ) ?? "{}" ) ?? [ ] ;
184178
185179 if ( section . ContainsKey ( key ) )
186180 {
187181 section . Remove ( key ) ;
188182 config [ sectionName ] = section ;
189- await SaveConfigurationAsync ( config ) ;
183+ await this . SaveConfigurationAsync ( config ) ;
190184 this . _logger . LogInformation ( "Key {Key} removed from section {SectionName}" , key , sectionName ) ;
191185 return true ;
192186 }
193187 }
188+
194189 return false ;
195190 }
196191 catch ( Exception ex )
0 commit comments