< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.FunctionScanners.AssemblyAgentFunctionScanner
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/FunctionScanners/AssemblyAgentFunctionScanner.cs
Line coverage
94%
Covered lines: 17
Uncovered lines: 1
Coverable lines: 18
Total lines: 43
Line coverage: 94.4%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
ScanForFunctionTypes()100%11100%
FromAssemblies(...)100%44100%
HasAgentFunctions(...)100%22100%
SafeGetTypes(...)100%1166.66%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/FunctionScanners/AssemblyAgentFunctionScanner.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Reflection;
 3
 4using NexusLabs.Needlr;
 5
 6namespace NexusLabs.Needlr.AgentFramework.FunctionScanners;
 7
 8[DoNotAutoRegister]
 9[RequiresUnreferencedCode("Assembly scanning uses reflection to discover types with [AgentFunction] methods.")]
 10[RequiresDynamicCode("Assembly scanning uses reflection APIs that may require dynamic code generation.")]
 1811internal sealed class AssemblyAgentFunctionScanner(
 1812    IReadOnlyList<Assembly> _assemblies) :
 13    IAgentFrameworkFunctionScanner
 14{
 15    public IReadOnlyList<Type> ScanForFunctionTypes()
 16    {
 1817        return FromAssemblies(_assemblies)
 1818            .Where(HasAgentFunctions)
 1819            .Distinct()
 1820            .ToArray();
 21    }
 22
 23    private static IEnumerable<Type> FromAssemblies(IEnumerable<Assembly> assemblies) =>
 1824        assemblies
 1825            .Where(a => !a.IsDynamic)
 1826            .SelectMany(SafeGetTypes)
 241227            .Where(t => t.IsClass && (!t.IsAbstract || t.IsStatic()));
 28
 29    private static bool HasAgentFunctions(Type t)
 30    {
 205231        var bindingFlags = t.IsStatic()
 205232            ? BindingFlags.Public | BindingFlags.Static
 205233            : BindingFlags.Public | BindingFlags.Instance;
 205234        return t.GetMethods(bindingFlags)
 1148435            .Any(m => m.IsDefined(typeof(AgentFunctionAttribute), inherit: true));
 36    }
 37
 38    private static IEnumerable<Type> SafeGetTypes(Assembly a)
 39    {
 1840        try { return a.GetTypes(); }
 041        catch (ReflectionTypeLoadException ex) { return ex.Types.Where(t => t is not null)!; }
 1842    }
 43}