< Summary

Information
Class: NexusLabs.Needlr.Injection.TypeFiltering
Assembly: NexusLabs.Needlr.Injection
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Injection/TypeFiltering.cs
Line coverage
100%
Covered lines: 16
Uncovered lines: 0
Coverable lines: 16
Total lines: 45
Line coverage: 100%
Branch coverage
100%
Covered branches: 30
Total branches: 30
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsConcreteType(...)100%2828100%
IsRecord(...)100%22100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Injection/TypeFiltering.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2
 3namespace NexusLabs.Needlr.Injection;
 4
 5/// <summary>
 6/// Provides helper methods for filtering types during dependency injection scanning.
 7/// </summary>
 8public static class TypeFiltering
 9{
 10    /// <summary>
 11    /// Determines if a type is a concrete type suitable for registration.
 12    /// This filters out abstract classes, interfaces, nested types, delegates, exceptions, attributes, etc.
 13    /// </summary>
 14    /// <param name="type">The type to check.</param>
 15    /// <returns>True if the type is a concrete type that can be instantiated.</returns>
 16    [RequiresUnreferencedCode("IsConcreteType calls IsRecord which uses reflection.")]
 17    public static bool IsConcreteType(Type type) =>
 67217918        type.IsClass &&
 67217919        !type.IsAbstract &&
 67217920        !type.IsGenericTypeDefinition &&
 67217921        !type.IsFunctionPointer &&
 67217922        !type.IsValueType &&
 67217923        !type.IsInterface &&
 67217924        !type.IsCOMObject &&
 67217925        !type.IsEnum &&
 67217926        !type.IsNested &&
 67217927        !type.IsAssignableTo(typeof(MulticastDelegate)) &&
 67217928        !type.IsAssignableTo(typeof(Exception)) &&
 67217929        !type.IsAssignableTo(typeof(Attribute)) &&
 67217930        !IsRecord(type) &&
 67217931        type.Name[0] != '<' && type.Name[^1] != '>' //t.GetCustomAttribute<CompilerGeneratedAttribute>() is null
 32        ;
 33
 34    /// <summary>
 35    /// Determines if a type is a record type.
 36    /// </summary>
 37    /// <param name="type">The type to check.</param>
 38    /// <returns>True if the type is a record.</returns>
 39    [RequiresUnreferencedCode("IsRecord uses Type.GetMethod which requires reflection.")]
 40    public static bool IsRecord(Type type)
 41    {
 12395642        return type.IsClass &&
 12395643               type.GetMethod("<Clone>$") is not null;
 44    }
 45}