RSCG – RxSourceGenerator

RSCG – RxSourceGenerator
 
 

name RxSourceGenerator
nuget https://www.nuget.org/packages/RxSourceGenerator/
link https://github.com/Zalutskii/Reactive-Extensions-event-generator
author Ivan Zalutskii

Generates RX Extensions for events

 

This is how you can use RxSourceGenerator .

The code that you start with is


<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>


The code that you will use is


// 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();


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);
    }

}


 

The code that is generated is

// <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 { }
}

Code and pdf at

https://ignatandrei.github.io/RSCG_Examples/v2/docs/RxSourceGenerator


Posted

in

, ,

by

Tags: