File tree Expand file tree Collapse file tree 3 files changed +12
-17
lines changed
csharp/getting-started/console-webapiclient Expand file tree Collapse file tree 3 files changed +12
-17
lines changed Original file line number Diff line number Diff line change 1
1
using System . Net . Http . Headers ;
2
- using System . Text . Json ;
2
+ using System . Net . Http . Json ;
3
3
4
4
using HttpClient client = new ( ) ;
5
5
client . DefaultRequestHeaders . Accept . Clear ( ) ;
22
22
23
23
static async Task < List < Repository > > ProcessRepositoriesAsync ( HttpClient client )
24
24
{
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 > ( ) ;
30
27
}
Original file line number Diff line number Diff line change 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
+ )
11
9
{
12
10
public DateTime LastPush => LastPushUtc . ToLocalTime ( ) ;
13
11
}
Original file line number Diff line number Diff line change 2
2
3
3
<PropertyGroup >
4
4
<OutputType >Exe</OutputType >
5
- <TargetFramework >net6 .0</TargetFramework >
5
+ <TargetFramework >net8 .0</TargetFramework >
6
6
<Nullable >enable</Nullable >
7
7
<ImplicitUsings >enable</ImplicitUsings >
8
8
</PropertyGroup >
You can’t perform that action at this time.
0 commit comments