LokiCat.R3.ObservableEvents 0.0.13

dotnet add package LokiCat.R3.ObservableEvents --version 0.0.13
                    
NuGet\Install-Package LokiCat.R3.ObservableEvents -Version 0.0.13
                    
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="LokiCat.R3.ObservableEvents" Version="0.0.13" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LokiCat.R3.ObservableEvents" Version="0.0.13" />
                    
Directory.Packages.props
<PackageReference Include="LokiCat.R3.ObservableEvents" />
                    
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 LokiCat.R3.ObservableEvents --version 0.0.13
                    
#r "nuget: LokiCat.R3.ObservableEvents, 0.0.13"
                    
#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 LokiCat.R3.ObservableEvents@0.0.13
                    
#: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=LokiCat.R3.ObservableEvents&version=0.0.13
                    
Install as a Cake Addin
#tool nuget:?package=LokiCat.R3.ObservableEvents&version=0.0.13
                    
Install as a Cake Tool

LokiCat.R3.ObservableEvents

R3-compatible source generator for turning C# event declarations into cached Observable<T> properties.

This package eliminates boilerplate when wiring up C# events into R3 reactive observables.
It generates cached, lazily-connected observables for every event declared on your partial interface or partial class.


โœจ Features

  • Automatically detects C# event declarations inside interfaces or classes
  • Generates type-safe Observable<T> or Observable<(T1, T2, ...)> properties
  • Supports events with 0 to 5 parameters
  • Emits clean diagnostic warnings for events with more than 5 parameters
  • Requires no manual Observable.Create logic
  • Fully R3 idiomatic: observables can be piped, composed, and disposed with AddTo(this)
  • Generated code respects your .editorconfig styling preferences

๐Ÿ“ฆ Installation

  1. Add this NuGet package to your project:
dotnet add package LokiCat.R3.ObservableEvents
  1. Define your events normally inside a partial interface or partial class:
public partial interface IPauseMenu
{
  event Action MainMenu;
  event Action Resume;
  event Action<Node, int> SaveProgress;
}
  1. Build your project. The generator will automatically emit:
private Observable<Unit> _onMainMenu;
public Observable<Unit> OnMainMenu =>
  Event(ref _onMainMenu, handler => MainMenu += handler);

private Observable<Unit> _onResume;
public Observable<Unit> OnResume =>
  Event(ref _onResume, handler => Resume += handler);

private Observable<(Node, int)> _onSaveProgress;
public Observable<(Node, int)> OnSaveProgress =>
  Event(ref _onSaveProgress, handler => SaveProgress += handler);

You can now subscribe:

pauseMenu.OnResume
  .Subscribe(() => Console.WriteLine("Game resumed"))
  .AddTo(this);

โœ… Supported Event Forms

Event form Generated Observable type
event Action Something() Observable<Unit>
event Action<Node> Something() Observable<Node>
event Action<Node, int> Something() Observable<(Node, int)>
... up to 5 args Observable<(T1, T2, ..., T5)>

Events with 6+ parameters will trigger a diagnostic warning and will not generate observables.


๐Ÿง  How It Works

  • The generator scans all syntax trees for event declarations.
  • It finds the corresponding delegate type (if external), and inspects its parameters.
  • It emits a private Observable<T> cache field and a public Observable<T> property.
  • It uses the Event(...) extension method to lazily subscribe and forward events into R3 pipelines.

๐Ÿ›  Example: Full Interface

public partial interface ISettingsMenu
{
  event Action Opened;
  event Action<string> LanguageChanged;
}

๐Ÿ”ป๏ธ Generates:

private Observable<Unit> _onOpened;
public Observable<Unit> OnOpened =>
  Event(ref _onOpened, handler => Opened += handler);

private Observable<string> _onLanguageChanged;
public Observable<string> OnLanguageChanged =>
  Event(ref _onLanguageChanged, handler => LanguageChanged += handler);

๐Ÿงช Troubleshooting

  • Your interfaces or classes must be marked partial
  • Events must use Action, Action<T>, or compatible delegate types
  • Check .g.cs output in obj/Debug/.../generated/
  • Use #nullable enable if you want null-safety
  • Rebuild your project to trigger generation

๐Ÿ“„ License

MIT License


๐Ÿ’ก Bonus Tip

Pair this generator with R3, and your own event-driven architectures to create clean, reactive, and highly composable C# APIs without boilerplate.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • net7.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
0.0.13 172 4/27/2025
0.0.12 172 4/27/2025
0.0.11 105 4/26/2025
0.0.10 107 4/26/2025
0.0.9 107 4/26/2025
0.0.7 107 4/26/2025