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 11using System . Net . Http . Headers ;
2- using System . Text . Json ;
2+ using System . Net . Http . Json ;
33
44using HttpClient client = new ( ) ;
55client . DefaultRequestHeaders . Accept . Clear ( ) ;
2222
2323static 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}
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+ )
119{
1210 public DateTime LastPush => LastPushUtc . ToLocalTime ( ) ;
1311}
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <OutputType >Exe</OutputType >
5- <TargetFramework >net6 .0</TargetFramework >
5+ <TargetFramework >net9 .0</TargetFramework >
66 <Nullable >enable</Nullable >
77 <ImplicitUsings >enable</ImplicitUsings >
88 </PropertyGroup >
You can’t perform that action at this time.
0 commit comments