You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature]: Support C# 15 closed classes (AreClosed / BeClosed) #519
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:
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 matchableClasses().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