Skip to main content

UnionsGenerator by Paul Braetz

Nuget / site data

Nuget GitHub last commit GitHub Repo stars

Details

Info

info

Name: UnionsGenerator

Generate hybrid (tagged/type) union types.

Author: Paul Braetz

NuGet: https://www.nuget.org/packages/RhoMicro.CodeAnalysis.UnionsGenerator

You can find more details at https://github.com/PaulBraetz/RhoMicro.CodeAnalysis/

Source : https://github.com/PaulBraetz/RhoMicro.CodeAnalysis/

Original Readme

note

Rhomicro.CodeAnalysis

Build

This repository contains my explorations on c# source code generation and analysis.

The [UnionsGenerator](https://github.com/PaulBraetz/RhoMicro.CodeAnalysis//UnionsGenerator generator enables the use of union types in C#.

The [UtilityGenerators](https://github.com/PaulBraetz/RhoMicro.CodeAnalysis//UtilityGenerators generator helps you write code generators and analyzers.

The [CopyTo](https://github.com/PaulBraetz/RhoMicro.CodeAnalysis//CopyTo generator generates methods to copy the contents of one instance to another. I created this generator for a friend, so it is not as feature rich as it could be.

About

note

Generating Union types for C#

How to use

Example ( source csproj, source files )

This is the CSharp Project that references UnionsGenerator

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)\GX</CompilerGeneratedFilesOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="RhoMicro.CodeAnalysis.UnionsGenerator" Version="14.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>

Generated Files

Those are taken from $(BaseIntermediateOutputPath)\GX

// <auto-generated>
// This file was generated by RhoMicro.CodeAnalysis.UnionsGenerator
// The tool used to generate this code may be subject to license terms;
// this generated code is however not subject to those terms, instead it is
// subject to the license (if any) applied to the containing project.
// </auto-generated>
#nullable enable
#pragma warning disable

namespace RhoMicro.CodeAnalysis
{
using System;

/// <summary>
/// Marks the target type to be related to another union type.
/// </summary>
/// <typeparam name="T0">The type to register as related to the target union type.</typeparam>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
#if UNIONS_GENERATOR
[GenerateFactory(OmitTypeCheck = true)]
#endif
sealed partial class RelationAttribute<T0> : Attribute
{ }
/// <summary>
/// Marks the target type to be related to other union types.
/// </summary>
/// <typeparam name="T0">The first type to register as related to the target union type.</typeparam>
/// <typeparam name="T1">The second type to register as related to the target union type.</typeparam>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
sealed partial class RelationAttribute<T0, T1> : Attribute
{ }
/// <summary>
/// Marks the target type to be related to other union types.
/// </summary>
/// <typeparam name="T0">The first type to register as related to the target union type.</typeparam>
/// <typeparam name="T1">The second type to register as related to the target union type.</typeparam>
/// <typeparam name="T2">The third type to register as related to the target union type.</typeparam>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
sealed partial class RelationAttribute<T0, T1, T2> : Attribute
{ }
/// <summary>
/// Marks the target type to be related to other union types.
/// </summary>
/// <typeparam name="T0">The first type to register as related to the target union type.</typeparam>
/// <typeparam name="T1">The second type to register as related to the target union type.</typeparam>
/// <typeparam name="T2">The third type to register as related to the target union type.</typeparam>
/// <typeparam name="T3">The fourth type to register as related to the target union type.</typeparam>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
sealed partial class RelationAttribute<T0, T1, T2, T3> : Attribute
{ }
/// <summary>
/// Marks the target type to be related to other union types.
/// </summary>
/// <typeparam name="T0">The first type to register as related to the target union type.</typeparam>
/// <typeparam name="T1">The second type to register as related to the target union type.</typeparam>
/// <typeparam name="T2">The third type to register as related to the target union type.</typeparam>
/// <typeparam name="T3">The fourth type to register as related to the target union type.</typeparam>
/// <typeparam name="T4">The fifth type to register as related to the target union type.</typeparam>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
sealed partial class RelationAttribute<T0, T1, T2, T3, T4> : Attribute
{ }
/// <summary>
/// Marks the target type to be related to other union types.
/// </summary>
/// <typeparam name="T0">The first type to register as related to the target union type.</typeparam>
/// <typeparam name="T1">The second type to register as related to the target union type.</typeparam>
/// <typeparam name="T2">The third type to register as related to the target union type.</typeparam>
/// <typeparam name="T3">The fourth type to register as related to the target union type.</typeparam>
/// <typeparam name="T4">The fifth type to register as related to the target union type.</typeparam>
/// <typeparam name="T5">The sixth type to register as related to the target union type.</typeparam>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
sealed partial class RelationAttribute<T0, T1, T2, T3, T4, T5> : Attribute
{ }
/// <summary>
/// Marks the target type to be related to other union types.
/// </summary>
/// <typeparam name="T0">The first type to register as related to the target union type.</typeparam>
/// <typeparam name="T1">The second type to register as related to the target union type.</typeparam>
/// <typeparam name="T2">The third type to register as related to the target union type.</typeparam>
/// <typeparam name="T3">The fourth type to register as related to the target union type.</typeparam>
/// <typeparam name="T4">The fifth type to register as related to the target union type.</typeparam>
/// <typeparam name="T5">The sixth type to register as related to the target union type.</typeparam>
/// <typeparam name="T6">The seventh type to register as related to the target union type.</typeparam>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
sealed partial class RelationAttribute<T0, T1, T2, T3, T4, T5, T6> : Attribute
{ }
/// <summary>
/// Marks the target type to be related to other union types.
/// </summary>
/// <typeparam name="T0">The first type to register as related to the target union type.</typeparam>
/// <typeparam name="T1">The second type to register as related to the target union type.</typeparam>
/// <typeparam name="T2">The third type to register as related to the target union type.</typeparam>
/// <typeparam name="T3">The fourth type to register as related to the target union type.</typeparam>
/// <typeparam name="T4">The fifth type to register as related to the target union type.</typeparam>
/// <typeparam name="T5">The sixth type to register as related to the target union type.</typeparam>
/// <typeparam name="T6">The seventh type to register as related to the target union type.</typeparam>
/// <typeparam name="T7">The eighth type to register as related to the target union type.</typeparam>
[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Class, AllowMultiple = true, Inherited = false)]
sealed partial class RelationAttribute<T0, T1, T2, T3, T4, T5, T6, T7> : Attribute
{ }
}

Usefull

Download Example (.NET C# )

Share UnionsGenerator

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

In the same category (FunctionalProgramming) - 10 other generators

cachesourcegenerator

dunet

Funcky.DiscriminatedUnion

FunicularSwitch

N.SourceGenerators.UnionTypes

OneOf

PartiallyApplied

RSCG_Utils_Memo

TypeUtilities

UnionGen