You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Readme.md
+4-8Lines changed: 4 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ JsonMergePatch library helps to deserialize http requests' and responses' json b
10
10
11
11
JsonMergePatch library is based on C# source generators. For the http body content to be deserialized into a type, the SourceGenerator library generates helper classes. Helper classes are called Wrappers, capturing all the features of the type intended to be used for the deserialization. Once the request is deserialized into a Wrapper object, the object can be used to apply the patch on the user defined target object. The JsonMergePatch library is designed to be used with POCO classes and record types.
12
12
13
-
Source Generations requires Visual Studio 16.9 or later.
13
+
Source Generations requires Visual Studio 17.12 or later.
14
14
15
15
Based on the given application type different packages may be installed from NuGet by running one or more of the following commands:
1. Add a new controller with a parameter types ```Patch<T>``` where ```T``` is a custom target type chosen by the user
27
+
1. Add a new controller with a parameter types ```Patch<T>``` where ```T``` is a custom target type chosen by the user. Make sure that `[Patchable]` is applied on the `T` target type.
28
28
1. Extend application startup
29
29
30
30
### Install AspNetCore packages via NuGet
@@ -58,7 +58,7 @@ public WeatherForecast PatchForecast(Patch<WeatherForecast> input)
58
58
}
59
59
```
60
60
61
-
During build, the source generator scans for methods with type parameters of ```Patch<T>```. When such a parameter is found a Wrapper type is generated for ```T```. The base class of the generated type provides the necessary operations to work with the type.
61
+
During build, the source generator scans types has `[Patchable]` attribute applied. When such a type is found a Wrapper type is generated for it.
62
62
63
63
### Extend application startup
64
64
@@ -86,9 +86,7 @@ The AspNetCore input reader supports requests with ```application/merge-patch+js
86
86
87
87
### Patchable
88
88
89
-
Certain use-cases require to generate wrapper types with the source generation for assemblies that do not directly use `Patch<T>` (where T is the wrapped source type). This could be a reason for having separate assemblies for entity types, or because of the need of stacking multiple source generators on top of each other.
90
-
In thie case types may be attributed with `[Patchable]` attribute:
91
-
89
+
To generate wrapper types with the source generation add the `[Patchable]` attribute:
92
90
```csharp
93
91
[Patchable]
94
92
publicclassWeatherForecast
@@ -97,8 +95,6 @@ public class WeatherForecast
97
95
}
98
96
```
99
97
100
-
`[Patchable]` makes sure to generate wrapper types for source types not used in HTTP requests or method arguments of `Patch<T>`.
101
-
102
98
### Using it with System.Text.Json source generation
103
99
104
100
In order to use multiple source generators, we need to *stack* them. Today the only way to do it is by enforcing a build order between two projects, while adding the first source generator to the first project built, and the second one to the second project built. To make sure JsonMergePatch source generator works with System.Text.Json's source generator create two projects:
0 commit comments