RxSourceGenerator by Ivan Zalutskii
NuGet / site data
Details
Info
Name: RxSourceGenerator
This package generates extension methods in the style of Reactive Extensions.
Author: Ivan Zalutskii
NuGet: https://www.nuget.org/packages/RxSourceGenerator/
You can find more details at https://github.com/Zalutskii/Reactive-Extensions-event-generator
Source: https://github.com/Zalutskii/Reactive-Extensions-event-generator
Author
Ivan Zalutskii
Original Readme
RxSourceGenerator
What is this?
This source code generator generates Reactive Extensions methods for class events. For example, there is some class with an event:
public partial class Example
{
public event Action<int, string, bool> ActionEvent;
}
If you enter the code:
Example example = new Example();
example.RxActionEvent()
The generator will create a file with extension methods:
using System;
using System.Reactive.Linq;
namespace RxMethodGenerator{
public static class RxGeneratedMethods{
public static IObservable<(System.Int32 Item1Int32, System.String Item2String, System.Boolean Item3Boolean)> RxActionEvent(this TestConsoleApp.Example obj)
{
if (obj == null) throw new ArgumentNullException(nameof(obj));
return Observable.FromEvent<System.Action<System.Int32, System.String, System.Boolean>, (System.Int32 Item1Int32, System.String Item2String, System.Boolean Item3Boolean)>(
conversion => (obj0, obj1, obj2) => conversion((obj0, obj1, obj2)),
h => obj.ActionEvent += h,
h => obj.ActionEvent -= h);
}
}
}
What does it look like in Visual Studio?

About
Generates RX Extensions for events
How to use
Example (source csproj, source files)
- CSharp Project
- Program.cs
- Person.cs
This is the CSharp Project that references RxSourceGenerator
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RxSourceGenerator" Version="2.0.1" />
<PackageReference Include="System.Reactive" Version="6.0.2" />
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
</Project>
This is the use of RxSourceGenerator in Program.cs
// See https://aka.ms/new-console-template for more information
using RxDemo;
using RxMethodGenerator;
Console.WriteLine("Hello, World!");
Person p=new Person();
//p.ActionEvent+= (a,b,c)=>
//{
// Console.WriteLine($"Into Event:{a},{b},{c}");
//};
p.RxActionEvent().Subscribe(t=>
{
Console.WriteLine($"into rx {t.Item1Int32},{t.Item2String},{t.Item3Boolean}");
});
p.DoAction(1,"2",true);
Console.ReadLine();
This is the use of RxSourceGenerator in Person.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RxDemo;
public partial class Person
{
public event Action<int, string, bool>? ActionEvent;
public void DoAction(int a, string b, bool c)
{
if(ActionEvent != null)
ActionEvent.Invoke(a, b, c);
}
}
Generated Files
Those are taken from $(BaseIntermediateOutputPath)\GX
- RxExtensionsForglobal__RxDemo_Person.g.cs
- RxGeneratedMethods.g.cs
// <auto-generated/>
using System;
using System.Reactive;
using System.Reactive.Linq;
namespace RxMethodGenerator
{
public static partial class RxGeneratedMethods
{
public static IObservable<(int Item1Int32, string Item2String, bool Item3Boolean)> RxActionEvent(this global::RxDemo.Person obj)
{
if (obj == null) throw new ArgumentNullException(nameof(obj));
return Observable.FromEvent<global::System.Action<int, string, bool>, (int Item1Int32, string Item2String, bool Item3Boolean)>(
conversion => (arg0, arg1, arg2) => conversion((arg0, arg1, arg2)),
h => obj.ActionEvent += h,
h => obj.ActionEvent -= h);
}
}
}
// <auto-generated/>
namespace RxMethodGenerator
{
public static partial class RxGeneratedMethods \{ }
}
Useful
Download Example (.NET C#)
Share RxSourceGenerator
https://ignatandrei.github.io/RSCG_Examples/v2/docs/RxSourceGenerator
aaa