Skip to content

Commit d5bbbce

Browse files
committed
replace GetValues with TryGetValues
1 parent ad80d80 commit d5bbbce

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

templates/dotnet/src/Appwrite/Client.cs.twig

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,11 @@ namespace {{ spec.title | caseUcfirst }}
232232
if (code >= 400) {
233233
var message = await response.Content.ReadAsStringAsync();
234234

235-
var contentType = response.Content.Headers
236-
.GetValues("Content-Type")
237-
.FirstOrDefault() ?? string.Empty;
235+
string contentType = string.Empty;
236+
if (response.Content.Headers.TryGetValues("Content-Type", out var contentTypes))
237+
{
238+
contentType = contentTypes.FirstOrDefault() ?? string.Empty;
239+
}
238240

239241
if (contentType.Contains("application/json")) {
240242
message = JObject.Parse(message)["message"]!.ToString();
@@ -267,9 +269,11 @@ namespace {{ spec.title | caseUcfirst }}
267269
var response = await _http.SendAsync(request);
268270
var code = (int)response.StatusCode;
269271

270-
var contentType = response.Content.Headers
271-
.GetValues("Content-Type")
272-
.FirstOrDefault() ?? string.Empty;
272+
string contentType = string.Empty;
273+
if (response.Content.Headers.TryGetValues("Content-Type", out var contentTypes))
274+
{
275+
contentType = contentTypes.FirstOrDefault() ?? string.Empty;
276+
}
273277

274278
var isJson = contentType.Contains("application/json");
275279

0 commit comments

Comments
 (0)