BenMorris/NetArchTest

Select types that are not inherited by any class

Opened this issue · 1 comments

Say I have a class that inherits from another, non-abstract, class:

public sealed class UserNotFoundException : UserException { }

public class UserException : Exception { }

This will break my assertion that class should be sealed:

var result = Types.InCurrentDomain()
    .And().AreNotInterfaces()
    .And().AreNotAbstract()
    .Should().BeSealed()
    .GetResult();

Rather than filtering edge-cases:

    .And().DoNotInherit(typeof(Exception)) 

is there any way to select types that are not inherited by any class? Like:

var result = Types.InCurrentDomain()
    .And().AreNotInterfaces()
    .And().AreNotAbstract()
    .And().AreNotInheritedByAnyClass()  // <--- like this
    .Should().BeSealed()
    .GetResult();

It is interesting use case. As far as I know, right now it is not supported, but it looks like doable, and could be added in the future to the NetArchTest.