Skip to content

[Feature]: Support C# 15 closed classes (AreClosed / BeClosed) #519

Open

Description

@mkay-sh

Description

C# 15 (.NET 11) adds closed classes. These are class hierarchies whose subclasses must all be declared in the same assembly, so a switch over them can be exhaustive:

public closed class Shape;
public sealed class Circle : Shape { public double Radius { get; init; } }
public sealed class Square : Shape { public double Side { get; init; } }

ArchUnitNET already loads these correctly. Shape shows up as an abstract Class, and both inheritance and the type checks inside switch expressions are found. However, rules can't tell a closed class apart from an ordinary abstract class.

The compiler marks the class with [System.Runtime.CompilerServices.IsClosedTypeAttribute].

Proposal, following AreSealed() / AreRecord():

  • an IsClosed property on Class
  • the predicates AreClosed() / AreNotClosed() and the conditions BeClosed() / NotBeClosed() on classes

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

Use Case(s)

// Event hierarchies must stay exhaustively matchable
Classes().That().AreAbstract().And().ResideInNamespace("MyApp.Domain.Events")
    .Should().BeClosed();

// Subclasses of closed classes are sealed
// (AreAssignableTo also matches the closed class itself, hence AreNotClosed)
Classes().That().AreAssignableTo(Classes().That().AreClosed())
    .And().AreNotClosed().Should().BeSealed();

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