Sstv.PartialUpdate 1.0.0

dotnet add package Sstv.PartialUpdate --version 1.0.0
                    
NuGet\Install-Package Sstv.PartialUpdate -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Sstv.PartialUpdate" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Sstv.PartialUpdate" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Sstv.PartialUpdate" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Sstv.PartialUpdate --version 1.0.0
                    
#r "nuget: Sstv.PartialUpdate, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Sstv.PartialUpdate@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Sstv.PartialUpdate&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Sstv.PartialUpdate&version=1.0.0
                    
Install as a Cake Tool

Sstv.PartialUpdate

A Roslyn source generator that automatically creates *Changes classes for partial entity updates in .NET applications.

Overview

Sstv.PartialUpdate generates change-tracking classes from your entities, enabling partial updates without manually creating separate DTOs. Perfect for PATCH APIs and scenarios where you need to update only specific fields.

Features

  • Automatic Code Generation: Generates *Changes classes from entities with [PartialUpdatable] attribute
  • Partial Updates: Track which fields were modified without sending the entire entity
  • Flexible JSON Parsing: Supports both numeric and string values for numeric types
  • Validation: Built-in null checking and type validation
  • Unread Changes Detection: Optional verification that all received changes were processed
  • Nullable Support: Full support for nullable reference and value types
  • Case Insensitive: Property name matching is case-insensitive

Installation

dotnet add package Sstv.PartialUpdate

Quick Start

1. Mark your entity properties

using Sstv.PartialUpdate;

public partial class User
{
    [PartialUpdatable]
    public string Name { get; set; } = string.Empty;

    [PartialUpdatable]
    public int Age { get; set; }

    [PartialUpdatable]
    public string? Email { get; set; }
}

2. Use the generated Changes class

using System.Text.Json;

// Parse JSON patch document
var json = """
    {
        "name": "John Doe",
        "age": 30
    }
    """;
var changes = JsonSerializer.Deserialize<Dictionary<string, JsonElement>>(json);

// Create changes object
var userChanges = UserChanges.From(changes);

// Check if a field was provided
if (userChanges.Name.IsDefined)
{
    Console.WriteLine($"New name: {userChanges.Name.Value}");
}

// Verify all fields were processed
userChanges.VerifyNoUnreadChanges();

Supported Types

  • Primitives: int, long, short, byte, sbyte, uint, ushort, ulong
  • Floating Point: float, double, decimal
  • Other: bool, string, Guid, DateTime, DateTimeOffset, TimeSpan
  • Arrays: byte[] (supports both Base64 string and JSON array formats)
  • Collections: List<T>, arrays of any supported type
  • Complex Types: Nested classes, records, structs implementing IParsable<TSelf>
  • Enums: Standard enums and nullable enums
  • Nullable: Full support for all nullable types

Advanced Usage

Skip unknown values

var result = UserChanges.From(changes, skipUnknownValues: true);

Non-nullable strings (throws on null)

[PartialUpdatable]
public string RequiredName { get; set; } = string.Empty;

// This will throw InvalidOperationException if null is passed

Verify unread changes

var changes = UserChanges.From(jsonDict);

// Process some fields...
var name = changes.Name.Value;

// This throws if 'age' was provided but not read
changes.VerifyNoUnreadChanges();

Configuration

The generated code includes:

  • AllProperties: Static HashSet<string> containing all updatable property names
  • SerializerOptions: Pre-configured JsonSerializerOptions with camelCase naming

Requirements

  • .NET Standard 2.0+ (works with .NET Framework 4.6.1+, .NET Core 2.0+, .NET 5+)
  • C# 10+

How It Works

The source generator runs at compile time and:

  1. Scans for classes with [PartialUpdatable] annotated properties
  2. Generates a partial *Changes class with Optional<T> properties for each marked field
  3. Creates a static From(Dictionary<string, JsonElement>) method for parsing JSON
  4. Adds helper methods like VerifyNoUnreadChanges()

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 63 5/17/2026