|
1 | | -using System; |
2 | | -using System.Net.Http; |
3 | | -using System.Threading.Tasks; |
4 | | -using ConsoleAppLibrary; |
| 1 | +using ConsoleAppLibrary; |
5 | 2 | using LaDeak.JsonMergePatch.Abstractions; |
6 | 3 | using LaDeak.JsonMergePatch.Http; |
7 | 4 |
|
8 | | -namespace ReadJsonPatchAsync |
| 5 | +namespace ReadJsonPatchAsync; |
| 6 | + |
| 7 | +public class Program |
9 | 8 | { |
10 | | - public class Program |
| 9 | + public class WeatherForecast |
11 | 10 | { |
12 | | - public class WeatherForecast |
13 | | - { |
14 | | - public DateTime Date { get; set; } |
15 | | - public int Temp { get; set; } |
16 | | - public string Summary { get; set; } |
17 | | - } |
| 11 | + public DateTime Date { get; set; } |
| 12 | + public int Temp { get; set; } |
| 13 | + public string Summary { get; set; } |
| 14 | + } |
18 | 15 |
|
19 | | - public static async Task Main(string[] args) |
20 | | - { |
21 | | - LaDeak.JsonMergePatch.Abstractions.JsonMergePatchOptions.Repository = LaDeak.JsonMergePatch.Generated.SafeConsoleApp.TypeRepository.Instance.Extend(LaDeak.JsonMergePatch.Generated.SafeConsoleAppLibrary.TypeRepository.Instance); |
22 | | - await ReadAsJsonMergePatchAsync(); |
23 | | - } |
| 16 | + public static async Task Main(string[] args) |
| 17 | + { |
| 18 | + LaDeak.JsonMergePatch.Abstractions.JsonMergePatchOptions.Repository = LaDeak.JsonMergePatch.Generated.Safe.TypeRepository.Instance.Extend(LaDeak.JsonMergePatch.Generated.SafeConsoleAppLibrary.TypeRepository.Instance); |
| 19 | + await ReadAsJsonMergePatchAsync(); |
| 20 | + } |
24 | 21 |
|
25 | | - public static async Task ReadAsJsonMergePatchAsync() |
26 | | - { |
27 | | - var httpClient = new HttpClient(); |
28 | | - var response = await httpClient.GetAsync("https://localhost:5001/Sample/Weather", HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); |
29 | | - var responseData = await response.Content.ReadJsonPatchAsync<WeatherForecast>().ConfigureAwait(false); |
30 | | - var target = new WeatherForecast() { Date = DateTime.UtcNow, Summary = "Sample weather forecast", Temp = 24 }; |
31 | | - var result = responseData.ApplyPatch(target); |
32 | | - Console.WriteLine($"Patched: Date={result.Date}, Summary={result.Summary}, Temp={result.Temp}"); |
| 22 | + public static async Task ReadAsJsonMergePatchAsync() |
| 23 | + { |
| 24 | + var httpClient = new HttpClient(); |
| 25 | + var response = await httpClient.GetAsync("https://localhost:5001/Sample/Weather", HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); |
| 26 | + var responseData = await response.Content.ReadJsonPatchAsync<WeatherForecast>().ConfigureAwait(false); |
| 27 | + var target = new WeatherForecast() { Date = DateTime.UtcNow, Summary = "Sample weather forecast", Temp = 24 }; |
| 28 | + var result = responseData.ApplyPatch(target); |
| 29 | + Console.WriteLine($"Patched: Date={result.Date}, Summary={result.Summary}, Temp={result.Temp}"); |
33 | 30 |
|
34 | | - var client = new Client(); |
35 | | - await client.ReadAsJsonMergePatchAsync(); |
36 | | - } |
| 31 | + var client = new Client(); |
| 32 | + await client.ReadAsJsonMergePatchAsync(); |
37 | 33 | } |
38 | 34 | } |
0 commit comments