CrowRx.Data.SourceGenerator 1.0.2

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

CrowRx.Data.SourceGenerator

A Roslyn Source Generator for the CrowRx.Data ecosystem. It automates the registration and initialization of data targets and sources, ensuring high-performance data routing with zero manual configuration.

Features

  • Automatic Discovery: Automatically finds all public, non-abstract classes implementing CrowRx.Data.ITarget.
  • Relationship Mapping: Detects ISource types from ITarget<TSource> interfaces, including support for arrays and List<T>.
  • Unity Lifecycle Integration: Automatically executes initialization after assemblies are loaded in Unity using [RuntimeInitializeOnLoadMethod].
  • Zero Boilerplate: Generates the necessary Managed<T>.Init() and Couple<S, T>.Init() calls at compile time.

API Reference

1. Generation Logic

The generator scans the compilation for types that satisfy the following:

  • Interface Implementation: Must implement CrowRx.Data.ITarget.
  • Accessibility: Must be public.
  • Concrete Type: Must not be abstract, an interface, or a generic type definition.

2. Type Extraction Rules

When an ITarget<TSource> interface is found, the generator identifies the underlying source type:

  • Direct Type: ITarget<MySource> registers MySource.
  • Arrays: ITarget<MySource[]> unwraps to register MySource.
  • Generic Collections: ITarget<List<MySource>> (or any single-argument generic) unwraps to register MySource.

3. Generated Hub (Generated.ManagedType)

A static class generated to handle system startup.

  • ManagedType.Initialize(): The main entry point that initializes all discovered targets and their relationships.
    • In Unity 6.0+: Automatically called via [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)].
    • Manual Call: Can be called manually in non-Unity environments to trigger registration.

Examples

Implementation Example

Define your data and targets normally. No extra code is needed for registration.

using CrowRx.Data;

// Define a Source
public struct InventorySource : ISource {
    public string ItemName;
}

// Define a Target
public class InventoryUI : ITarget<InventorySource> {
    public bool UpdateBy(in InventorySource source) {
        UnityEngine.Debug.Log($"Received item: {source.ItemName}");
        return true;
    }
}

Generated Code Structure

The generator will automatically output a file ManagedType.g.cs:

// <auto-generated />
using CrowRx.Data;
#if UNITY_6000_0_OR_NEWER
using UnityEngine;
#endif

namespace Generated {
    internal static class ManagedType {
#if UNITY_6000_0_OR_NEWER
        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)]
#endif
        public static void Initialize() {
            #region generated managed
            // Initializes the target manager
            Managed<Global.InventoryUI>.Init();

            // Maps the source to the target
            Couple<Global.InventorySource, Global.InventoryUI>.Init();
            #endregion
        }
    }
}

Requirements

  • Unity 6.0 or newer (for automatic execution).
  • .NET Standard 2.0 (compatible with most Unity environments).
  • CrowRx.Data: The runtime library must be present.

License

This project is licensed under the MIT License.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on CrowRx.Data.SourceGenerator:

Package Downloads
CrowRx.Data

A global reactive system library for CrowRx. This package is intended for use with Unity3D 6.0 or newer only.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 188 3/11/2026
1.0.1 301 2/12/2026
1.0.0 106 2/12/2026