diff --git a/csharp/getting-started/console-webapiclient/Program.cs b/csharp/getting-started/console-webapiclient/Program.cs index 141266bb4e3..eee777bdc50 100644 --- a/csharp/getting-started/console-webapiclient/Program.cs +++ b/csharp/getting-started/console-webapiclient/Program.cs @@ -1,5 +1,5 @@ using System.Net.Http.Headers; -using System.Text.Json; +using System.Net.Http.Json; using HttpClient client = new(); client.DefaultRequestHeaders.Accept.Clear(); @@ -22,9 +22,6 @@ static async Task> ProcessRepositoriesAsync(HttpClient client) { - await using Stream stream = - await client.GetStreamAsync("https://api.github.com/orgs/dotnet/repos"); - var repositories = - await JsonSerializer.DeserializeAsync>(stream); - return repositories ?? new(); + var repositories = await client.GetFromJsonAsync>("https://api.github.com/orgs/dotnet/repos"); + return repositories ?? new List(); } diff --git a/csharp/getting-started/console-webapiclient/Repository.cs b/csharp/getting-started/console-webapiclient/Repository.cs index b43527db56f..cd2d4e559dc 100644 --- a/csharp/getting-started/console-webapiclient/Repository.cs +++ b/csharp/getting-started/console-webapiclient/Repository.cs @@ -1,13 +1,11 @@ -using System; -using System.Text.Json.Serialization; - -public sealed record class Repository( - [property: JsonPropertyName("name")] string Name, - [property: JsonPropertyName("description")] string Description, - [property: JsonPropertyName("html_url")] Uri GitHubHomeUrl, - [property: JsonPropertyName("homepage")] Uri Homepage, - [property: JsonPropertyName("watchers")] int Watchers, - [property: JsonPropertyName("pushed_at")] DateTime LastPushUtc) +public record class Repository( + string Name, + string Description, + Uri GitHubHomeUrl, + Uri Homepage, + int Watchers, + DateTime LastPushUtc +) { public DateTime LastPush => LastPushUtc.ToLocalTime(); } diff --git a/csharp/getting-started/console-webapiclient/webapiclient.csproj b/csharp/getting-started/console-webapiclient/webapiclient.csproj index cba1ce1334c..93d988e5f1a 100644 --- a/csharp/getting-started/console-webapiclient/webapiclient.csproj +++ b/csharp/getting-started/console-webapiclient/webapiclient.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net9.0 enable enable