PTrampert.SimplePatch
1.1.15
See the version list below for details.
dotnet add package PTrampert.SimplePatch --version 1.1.15
NuGet\Install-Package PTrampert.SimplePatch -Version 1.1.15
<PackageReference Include="PTrampert.SimplePatch" Version="1.1.15" />
<PackageVersion Include="PTrampert.SimplePatch" Version="1.1.15" />
<PackageReference Include="PTrampert.SimplePatch" />
paket add PTrampert.SimplePatch --version 1.1.15
#r "nuget: PTrampert.SimplePatch, 1.1.15"
#:package PTrampert.SimplePatch@1.1.15
#addin nuget:?package=PTrampert.SimplePatch&version=1.1.15
#tool nuget:?package=PTrampert.SimplePatch&version=1.1.15
PTrampert.SimplePatch
Library supporting simple patch objects in .NET.
Overview
PTrampert.SimplePatch is a C# library designed to facilitate the handling of flat PATCH objects in .NET web applications. With this library, you can easily distinguish between properties that are omitted from a PATCH request and those explicitly set to null or a value.
This is especially useful when you want to update only specific properties of an object, leaving others unchanged. For example, if you send a PATCH request like:
{
"name": "New Name"
}
and your object contains additional properties besides name, PTrampert.SimplePatch makes it easy to ensure that only name is updated, and all other properties remain untouched.
Features
- Supports "Optional" types for PATCH operations.
- Dynamically generates implementations of
IPatchObjectfor your write models. - Preserves validation attributes on properties, allowing for validation of PATCH requests.
- Handles complex types with custom JSON converters.
Getting Started
A full sample project is available in the PTrampert.SimplePatch.Samples
- Install the library via NuGet:
dotnet add package PTrampert.SimplePatch
- Create your write model class
public record PersonWriteModel
{
// For PATCH requests, Required will only be enforced if the property is present in the request body.
[Required]
[StringLength(255, MinimumLength = 3)]
public required string Name { get; init; }
public DateTime DateOfBirth { get; init; }
// Validation attributes can be used to enforce rules on the email field.
[EmailAddress]
public string? Email { get; init; }
// Using a custom JSON converter to handle phone number serialization and deserialization
[JsonConverter(typeof(PhoneNumberJsonConverter))]
public PhoneNumber? PhoneNumber { get; init; }
}
- Use
IPatchObject<PersonWriteModel>to create an optional object for PATCH operations:
[HttpPatch("{id:int}")]
public ActionResult<PersonReadModel> PatchPerson(
int id,
// PTrampert.SimplePatch automatically generates an implementation of IPatchObject<PersonWriteModel>
[FromBody] IPatchObject<PersonWriteModel> patchObject)
{
// Validation is preserved on the patch object, so we can check ModelState
if (!ModelState.IsValid)
return BadRequest(ModelState);
var existingPerson = _db.GetPersonById(id);
if (existingPerson == null)
return NotFound();
var patchedPerson = patchObject.Patch(existingPerson);
var updatedPerson = _db.UpdatePerson(id, patchedPerson);
return updatedPerson!;
}
This will allow you to make the following HTTP request to update only the specified properties of Person (in this example, only the 'name' property).
PATCH /person/1 HTTP/1.1
Content-Type: application/json
Content-Length: 24
{
"name": "New Name"
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.CodeAnalysis.CSharp (>= 4.14.0)
- Microsoft.CodeDom.Providers.DotNetCompilerPlatform (>= 4.1.0)
- System.CodeDom (>= 9.0.8)
- System.Text.Json (>= 9.0.8)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on PTrampert.SimplePatch:
| Package | Downloads |
|---|---|
|
PTrampert.SimplePatch.Schema
Shared OpenAPI schema generation for PTrampert.SimplePatch. Referenced by the Swashbuckle and Microsoft.AspNetCore.OpenApi integration packages; not usually installed directly. |
|
|
PTrampert.SimplePatch.OpenApi
Microsoft.AspNetCore.OpenApi integration for PTrampert.SimplePatch. Documents routes taking an IPatchObject<T> with the patched model's schema instead of an empty object. |
|
|
PTrampert.SimplePatch.Swashbuckle
Swashbuckle integration for PTrampert.SimplePatch. Documents routes taking an IPatchObject<T> with the patched model's schema instead of an empty object. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.1 | 134 | 9/12/2026 |
| 1.2.0 | 128 | 9/12/2026 |
| 1.1.15 | 90 | 9/12/2026 |
| 1.1.14 | 109 | 8/7/2026 |
| 1.1.13 | 133 | 6/11/2026 |
| 1.1.12 | 164 | 1/10/2026 |
| 1.1.11 | 139 | 1/10/2026 |
| 1.1.10 | 138 | 1/6/2026 |
| 1.1.9 | 231 | 11/27/2025 |
| 1.1.8 | 264 | 11/14/2025 |
| 1.1.7 | 185 | 10/31/2025 |
| 1.1.6 | 236 | 10/13/2025 |
| 1.1.5 | 231 | 10/9/2025 |
| 1.1.4 | 226 | 10/9/2025 |
| 1.1.3 | 243 | 10/9/2025 |
| 1.1.2 | 231 | 10/3/2025 |
| 1.1.1 | 222 | 10/2/2025 |
| 1.1.0 | 227 | 10/2/2025 |
| 1.0.5 | 219 | 10/2/2025 |
| 1.0.4 | 364 | 9/19/2025 |