-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ladeak
committed
Oct 9, 2024
1 parent
9ef122f
commit 418c6d4
Showing
49 changed files
with
514 additions
and
638 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,34 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using ConsoleAppLibrary; | ||
using ConsoleAppLibrary; | ||
using LaDeak.JsonMergePatch.Abstractions; | ||
using LaDeak.JsonMergePatch.Http; | ||
|
||
namespace ReadJsonPatchAsync | ||
namespace ReadJsonPatchAsync; | ||
|
||
public class Program | ||
{ | ||
public class Program | ||
public class WeatherForecast | ||
{ | ||
public class WeatherForecast | ||
{ | ||
public DateTime Date { get; set; } | ||
public int Temp { get; set; } | ||
public string Summary { get; set; } | ||
} | ||
public DateTime Date { get; set; } | ||
public int Temp { get; set; } | ||
public string Summary { get; set; } | ||
} | ||
|
||
public static async Task Main(string[] args) | ||
{ | ||
LaDeak.JsonMergePatch.Abstractions.JsonMergePatchOptions.Repository = LaDeak.JsonMergePatch.Generated.SafeConsoleApp.TypeRepository.Instance.Extend(LaDeak.JsonMergePatch.Generated.SafeConsoleAppLibrary.TypeRepository.Instance); | ||
await ReadAsJsonMergePatchAsync(); | ||
} | ||
public static async Task Main(string[] args) | ||
{ | ||
LaDeak.JsonMergePatch.Abstractions.JsonMergePatchOptions.Repository = LaDeak.JsonMergePatch.Generated.SafeConsoleApp.TypeRepository.Instance.Extend(LaDeak.JsonMergePatch.Generated.SafeConsoleAppLibrary.TypeRepository.Instance); | ||
await ReadAsJsonMergePatchAsync(); | ||
} | ||
|
||
public static async Task ReadAsJsonMergePatchAsync() | ||
{ | ||
var httpClient = new HttpClient(); | ||
var response = await httpClient.GetAsync("https://localhost:5001/Sample/Weather", HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); | ||
var responseData = await response.Content.ReadJsonPatchAsync<WeatherForecast>().ConfigureAwait(false); | ||
var target = new WeatherForecast() { Date = DateTime.UtcNow, Summary = "Sample weather forecast", Temp = 24 }; | ||
var result = responseData.ApplyPatch(target); | ||
Console.WriteLine($"Patched: Date={result.Date}, Summary={result.Summary}, Temp={result.Temp}"); | ||
public static async Task ReadAsJsonMergePatchAsync() | ||
{ | ||
var httpClient = new HttpClient(); | ||
var response = await httpClient.GetAsync("https://localhost:5001/Sample/Weather", HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); | ||
var responseData = await response.Content.ReadJsonPatchAsync<WeatherForecast>().ConfigureAwait(false); | ||
var target = new WeatherForecast() { Date = DateTime.UtcNow, Summary = "Sample weather forecast", Temp = 24 }; | ||
var result = responseData.ApplyPatch(target); | ||
Console.WriteLine($"Patched: Date={result.Date}, Summary={result.Summary}, Temp={result.Temp}"); | ||
|
||
var client = new Client(); | ||
await client.ReadAsJsonMergePatchAsync(); | ||
} | ||
var client = new Client(); | ||
await client.ReadAsJsonMergePatchAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,22 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using LaDeak.JsonMergePatch.Http; | ||
using LaDeak.JsonMergePatch.Http; | ||
|
||
namespace ConsoleAppLibrary | ||
namespace ConsoleAppLibrary; | ||
|
||
public class DeviceData | ||
{ | ||
public class DeviceData | ||
{ | ||
public double Watts { get; set; } | ||
public string Name { get; set; } | ||
} | ||
public double Watts { get; set; } | ||
public string Name { get; set; } | ||
} | ||
|
||
public class Client | ||
public class Client | ||
{ | ||
public async Task ReadAsJsonMergePatchAsync() | ||
{ | ||
public async Task ReadAsJsonMergePatchAsync() | ||
{ | ||
var httpClient = new HttpClient(); | ||
var response = await httpClient.GetAsync("https://localhost:5001/Sample/DeviceData", HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); | ||
var responseData = await response.Content.ReadJsonPatchAsync<DeviceData>().ConfigureAwait(false); | ||
var target = new DeviceData() { Watts = 5, Name = "phone" }; | ||
var result = responseData.ApplyPatch(target); | ||
Console.WriteLine($"Patched: Name={result.Name}, Watts={result.Watts}"); | ||
} | ||
var httpClient = new HttpClient(); | ||
var response = await httpClient.GetAsync("https://localhost:5001/Sample/DeviceData", HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false); | ||
var responseData = await response.Content.ReadJsonPatchAsync<DeviceData>().ConfigureAwait(false); | ||
var target = new DeviceData() { Watts = 5, Name = "phone" }; | ||
var result = responseData.ApplyPatch(target); | ||
Console.WriteLine($"Patched: Name={result.Name}, Watts={result.Watts}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.