-
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.
Merge pull request #14 from ladeak/multi_library
Multi library support
- Loading branch information
Showing
25 changed files
with
410 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\JsonMergePatch.Http\JsonMergePatch.Http.csproj" /> | ||
<ProjectReference Include="..\..\src\JsonMergePatch.SourceGenerator\JsonMergePatch.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using LaDeak.JsonMergePatch.Http; | ||
|
||
namespace ConsoleAppLibrary | ||
{ | ||
public class DeviceData | ||
{ | ||
public double Watts { get; set; } | ||
public string Name { get; set; } | ||
} | ||
|
||
public class Client | ||
{ | ||
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 original = new DeviceData() { Watts = 5, Name = "phone" }; | ||
var result = responseData.ApplyPatch(original); | ||
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
20 changes: 20 additions & 0 deletions
20
src/JsonMergePatch.Abstractions/ITypeRepositoryExtensions.cs
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace LaDeak.JsonMergePatch.Abstractions | ||
{ | ||
public static class ITypeRepositoryExtensions | ||
{ | ||
public static ITypeRepository Extend(this ITypeRepository target, ITypeRepository source) | ||
{ | ||
_ = target ?? throw new ArgumentNullException(nameof(target)); | ||
_ = source ?? throw new ArgumentNullException(nameof(source)); | ||
|
||
foreach (var item in source.GetAll() ?? Enumerable.Empty<KeyValuePair<Type, Type>>()) | ||
if (!target.TryGet(item.Key, out _)) | ||
target.Add(item.Key, item.Value); | ||
return target; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace LaDeak.JsonMergePatch.SourceGenerator | ||
{ | ||
public static class NameBuilder | ||
{ | ||
private const string Namespace = "LaDeak.JsonMergePatch.Generated"; | ||
|
||
public static string GetName(ITypeSymbol typeInfo) => $"{typeInfo.Name}Wrapped"; | ||
|
||
public static string GetNamespaceExtension(ITypeSymbol typeInfo) => $"Safe{typeInfo.ContainingNamespace.ToDisplayString()}"; | ||
|
||
public static string GetFullTypeName(ITypeSymbol typeInfo) => $"{Namespace}.{GetNamespaceExtension(typeInfo)}.{GetName(typeInfo)}"; | ||
|
||
public static string GetNamespace(ITypeSymbol typeInfo) => $"{Namespace}.{GetNamespaceExtension(typeInfo)}"; | ||
|
||
public static string GetNamespace(string extension) => $"{Namespace}.Safe{extension}"; | ||
} | ||
} |
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.