< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.FunctionScanners.AssemblyAgentFunctionGroupScanner
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/FunctionScanners/AssemblyAgentFunctionGroupScanner.cs
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 41
Line coverage: 93.3%
Branch coverage
100%
Covered branches: 14
Total branches: 14
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%
ScanForFunctionGroups()100%141492.85%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/FunctionScanners/AssemblyAgentFunctionGroupScanner.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 [AgentFunctionGroup] attributes.")]
 10[RequiresDynamicCode("Assembly scanning uses reflection APIs that may require dynamic code generation.")]
 1011internal sealed class AssemblyAgentFunctionGroupScanner(IReadOnlyList<Assembly> _assemblies)
 12{
 13    public IReadOnlyDictionary<string, IReadOnlyList<Type>> ScanForFunctionGroups()
 14    {
 1015        var groups = new Dictionary<string, List<Type>>();
 16
 5017        foreach (var assembly in _assemblies.Where(a => !a.IsDynamic))
 18        {
 19            IEnumerable<Type> types;
 2020            try { types = assembly.GetTypes(); }
 021            catch (ReflectionTypeLoadException ex) { types = ex.Types.Where(t => t is not null)!; }
 22
 363023            foreach (var type in types.Where(t => t.IsClass && (!t.IsAbstract || t.IsStatic())))
 24            {
 132025                foreach (AgentFunctionGroupAttribute attr in
 114026                    type.GetCustomAttributes<AgentFunctionGroupAttribute>(inherit: false))
 27                {
 9028                    if (!groups.TryGetValue(attr.GroupName, out var list))
 8029                        groups[attr.GroupName] = list = [];
 30
 9031                    if (!list.Contains(type))
 9032                        list.Add(type);
 33                }
 34            }
 35        }
 36
 1037        return groups.ToDictionary(
 8038            k => k.Key,
 9039            v => (IReadOnlyList<Type>)v.Value.AsReadOnly());
 40    }
 41}