Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions csharp/getting-started/console-webapiclient/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
Expand All @@ -22,9 +22,6 @@

static async Task<List<Repository>> ProcessRepositoriesAsync(HttpClient client)
{
await using Stream stream =
await client.GetStreamAsync("https://api.github.com/orgs/dotnet/repos");
var repositories =
await JsonSerializer.DeserializeAsync<List<Repository>>(stream);
return repositories ?? new();
var repositories = await client.GetFromJsonAsync<List<Repository>>("https://api.github.com/orgs/dotnet/repos");
return repositories ?? new List<Repository>();
}
18 changes: 8 additions & 10 deletions csharp/getting-started/console-webapiclient/Repository.cs
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
Expand Down
Loading