ZeroAlloc.Notify.Generator
2.0.0
See the version list below for details.
dotnet add package ZeroAlloc.Notify.Generator --version 2.0.0
NuGet\Install-Package ZeroAlloc.Notify.Generator -Version 2.0.0
<PackageReference Include="ZeroAlloc.Notify.Generator" Version="2.0.0"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
<PackageVersion Include="ZeroAlloc.Notify.Generator" Version="2.0.0" />
<PackageReference Include="ZeroAlloc.Notify.Generator"> <PrivateAssets>all</PrivateAssets> <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets> </PackageReference>
paket add ZeroAlloc.Notify.Generator --version 2.0.0
#r "nuget: ZeroAlloc.Notify.Generator, 2.0.0"
#:package ZeroAlloc.Notify.Generator@2.0.0
#addin nuget:?package=ZeroAlloc.Notify.Generator&version=2.0.0
#tool nuget:?package=ZeroAlloc.Notify.Generator&version=2.0.0
ZeroAlloc.Notify
Source-generated, awaitable INotifyPropertyChanged for .NET: await vm.SetNameAsync("Alice") returns only after every async handler has finished, with no reflection and NativeAOT support.
Why ZeroAlloc.Notify
- Setters you can
await. Async validation, saving or coordinated state changes complete before the setter returns. CommunityToolkit.Mvvm and PropertyChanged.Fody only offer synchronous notifications. - 0 B per change, with or without subscribers, for reference-type properties and value types of up to 16 bytes without references, such as
int,decimalorGuid. The property event args are structs, and their old and new values keep such a value type inline instead of boxing it; tests assert 0 B for sequential and parallel dispatch with synchronous handlers. A larger struct, or one that contains references, is boxed once per value. - Works under NativeAOT and trimming. All plumbing is generated at compile time; CI publishes and runs a NativeAOT sample on every build.
- Compile-time diagnostics. A class that is not
partial, a record, or a stray[ObservableProperty]is reported by the build, not discovered at runtime.
Install
dotnet add package ZeroAlloc.Notify
The source generator ships inside the package.
Quick start
using ZeroAlloc.Notify;
var user = new UserViewModel();
user.PropertyChangedAsync += async (args, ct) =>
{
await Task.Delay(100, ct); // e.g. save to a server
Console.WriteLine($"{args.PropertyName}: {args.OldValue} -> {args.NewValue}, saved");
};
await user.SetNameAsync("Alice"); // returns after the handler has saved
await user.SetAgeAsync(30);
[NotifyPropertyChangedAsync]
public partial class UserViewModel
{
[ObservableProperty] private string _name = "";
[ObservableProperty] private int _age;
}
The generator writes the Name and Age properties, the SetNameAsync and SetAgeAsync setters and the PropertyChangedAsync event.
What you get
- Async property notifications, before and after a change:
[NotifyPropertyChangedAsync]and[NotifyPropertyChangingAsync]. Observable properties - Async collection notifications with
[NotifyCollectionChangedAsync]. Collection changes - Async validation through
INotifyDataErrorInfoAsync. Validation - Parallel handlers by default, sequential on request with
[InvokeSequentially], and aCancellationTokenon every setter. Async notifications - Build-time checks, ZAN001 to ZAN006. Diagnostics
- Typed old and new values:
args.NewValue.As<int>()reads a value without boxing it. Observable properties - Targets
net10.0andnet11.0. - Built on ZeroAlloc.AsyncEvents, the async event primitive behind every handler.
Performance
One property change with five handlers attached, .NET 10, all four libraries in one BenchmarkDotNet run. Allocations are exact; the ratio is each library's time against a hand-written INotifyPropertyChanged in the same run. Absolute timings are not published.
| Library | Ratio | Allocated | Async handlers |
|---|---|---|---|
Manual INotifyPropertyChanged |
1.00 | 24 B | no |
| PropertyChanged.Fody | 0.76 | 0 B | no |
| CommunityToolkit.Mvvm | 1.35 | 0 B | no |
| ZeroAlloc.Notify | 1.52 | 0 B | yes |
Awaitable handlers have a cost: Notify is slower than hand-written code, Fody and CommunityToolkit.Mvvm. For purely synchronous view models, Fody is the faster choice. Measured with version 2.0 on a GitHub-hosted runner; the test suite also gates the 0 B. Allocation breakdown, design notes and full numbers: docs/performance.md.
Learn more
- Documentation: notify.zeroalloc.net
- Runnable example:
samples/ZeroAlloc.Notify.AotSmoke, published with NativeAOT in CI - Related packages: ZeroAlloc.AsyncEvents and the rest of the ZeroAlloc family
- Contributing: issues and pull requests are welcome on GitHub
- License: MIT
Learn more about Target Frameworks and .NET Standard.
This package has 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 |
|---|---|---|
| 2.0.2 | 54 | 11/23/2026 |
| 2.0.1 | 58 | 11/22/2026 |
| 2.0.0 | 55 | 11/22/2026 |
| 1.3.1 | 92 | 11/17/2026 |
| 1.3.0 | 88 | 11/11/2026 |
| 1.2.14 | 103 | 10/22/2026 |
| 1.2.13 | 95 | 10/16/2026 |
| 1.2.12 | 104 | 10/15/2026 |
| 1.2.11 | 99 | 10/12/2026 |
| 1.2.10 | 94 | 10/11/2026 |
| 1.2.9 | 107 | 9/30/2026 |
| 1.2.8 | 101 | 9/28/2026 |
| 1.2.7 | 104 | 9/20/2026 |
| 1.2.6 | 112 | 9/20/2026 |
| 1.2.5 | 108 | 9/20/2026 |
| 1.2.4 | 113 | 9/19/2026 |
| 1.2.3 | 132 | 8/7/2026 |
| 1.2.2 | 134 | 5/13/2026 |
| 1.2.1 | 130 | 5/12/2026 |
| 1.2.0 | 125 | 5/3/2026 |