Skip to content

Commit d7ee36c

Browse files
Adjust the samples code so that it matches the refactored tutorial
1 parent 5539421 commit d7ee36c

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

csharp/getting-started/console-webapiclient/Program.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using System.Net.Http.Headers;
2-
using System.Text.Json;
2+
using System.Net.Http.Json;
33

44
using HttpClient client = new();
55
client.DefaultRequestHeaders.Accept.Clear();
@@ -22,9 +22,6 @@
2222

2323
static async Task<List<Repository>> ProcessRepositoriesAsync(HttpClient client)
2424
{
25-
await using Stream stream =
26-
await client.GetStreamAsync("https://api.github.com/orgs/dotnet/repos");
27-
var repositories =
28-
await JsonSerializer.DeserializeAsync<List<Repository>>(stream);
29-
return repositories ?? new();
25+
var repositories = await client.GetFromJsonAsync<List<Repository>>("https://api.github.com/orgs/dotnet/repos");
26+
return repositories ?? new List<Repository>();
3027
}
Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
using System;
2-
using System.Text.Json.Serialization;
3-
4-
public sealed record class Repository(
5-
[property: JsonPropertyName("name")] string Name,
6-
[property: JsonPropertyName("description")] string Description,
7-
[property: JsonPropertyName("html_url")] Uri GitHubHomeUrl,
8-
[property: JsonPropertyName("homepage")] Uri Homepage,
9-
[property: JsonPropertyName("watchers")] int Watchers,
10-
[property: JsonPropertyName("pushed_at")] DateTime LastPushUtc)
1+
public record class Repository(
2+
string Name,
3+
string Description,
4+
Uri GitHubHomeUrl,
5+
Uri Homepage,
6+
int Watchers,
7+
DateTime LastPushUtc
8+
)
119
{
1210
public DateTime LastPush => LastPushUtc.ToLocalTime();
1311
}

csharp/getting-started/console-webapiclient/webapiclient.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net6.0</TargetFramework>
5+
<TargetFramework>net8.0</TargetFramework>
66
<Nullable>enable</Nullable>
77
<ImplicitUsings>enable</ImplicitUsings>
88
</PropertyGroup>

0 commit comments

Comments
 (0)