Skip to content

[Feature]: Support C# 15 union types (AreUnions / BeUnions) #520

Open

Description

@mkay-sh

Description

C# 15 (.NET 11) adds union types:

public record Cat(string Name);
public record Dog(int Age);

public union Pet(Cat, Dog);

ArchUnitNET already loads these correctly. A union shows up as a Struct with one constructor per case type and a Value property. Dependencies are found both from the union to its case types and from code that switches over the union. The only gap is that rules can't tell a union apart from an ordinary struct.

The compiler marks a union type with:

  • [System.Runtime.CompilerServices.UnionAttribute]
  • the interface System.Runtime.CompilerServices.IUnion

Proposal:

  • an IsUnion property on the type
  • the predicates AreUnions() / AreNotUnions() and the conditions BeUnions() / NotBeUnions() on types, next to AreStructs()

I'd be happy to implement this and open a PR if the proposal sounds good to you.

Use Case(s)

// Unions only in the domain model
Types().That().AreUnions().Should().ResideInNamespace("MyApp.Domain");

// Results are unions, not inheritance hierarchies
Types().That().HaveNameEndingWith("Result").Should().BeUnions();

Activity

  1. added
    kind/featureCategorizes issue or PR as related to a new feature.
    needs-triageIndicates that an issue needs to be categorized.
    on Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.needs-triageIndicates that an issue needs to be categorized.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions