< Summary

Information
Class: NexusLabs.Needlr.Injection.Reflection.Loaders.FileMatchAssemblyLoader
Assembly: NexusLabs.Needlr.Injection.Reflection
File(s): /actions-runner/_work/needlr/needlr/src/NexusLabs.Needlr.Injection.Reflection/Loaders/FileMatchAssemblyLoader.cs
Line coverage
97%
Covered lines: 36
Uncovered lines: 1
Coverable lines: 37
Total lines: 64
Line coverage: 97.2%
Branch coverage
50%
Covered branches: 1
Total branches: 2
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
LoadAssemblies(...)50%2296.55%

File(s)

/actions-runner/_work/needlr/needlr/src/NexusLabs.Needlr.Injection.Reflection/Loaders/FileMatchAssemblyLoader.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Reflection;
 3
 4namespace NexusLabs.Needlr.Injection.Reflection.Loaders;
 5
 6/// <summary>
 7/// Assembly loader that loads assemblies from disk based on file name matching.
 8/// </summary>
 9/// <remarks>
 10/// This loader is not compatible with NativeAOT or trimming. For AOT scenarios,
 11/// use GeneratedAssemblyProvider from NexusLabs.Needlr.Injection.SourceGen instead.
 12/// </remarks>
 13[RequiresUnreferencedCode("FileMatchAssemblyLoader uses Assembly.LoadFrom which is not AOT-compatible. Use GeneratedAsse
 14public sealed class FileMatchAssemblyLoader : IAssemblyLoader
 15{
 16    private readonly IReadOnlyList<string> _directories;
 17    private readonly Predicate<string> _fileFilter;
 18
 38319    public FileMatchAssemblyLoader(
 38320        IReadOnlyList<string> directories,
 38321        Predicate<string>? fileFilter)
 22    {
 38323        ArgumentNullException.ThrowIfNull(directories);
 38224        ArgumentNullException.ThrowIfNull(fileFilter);
 25
 38126        _directories = directories;
 38127        _fileFilter = fileFilter;
 38128    }
 29
 30    /// <inheritdoc />
 31    public IReadOnlyList<Assembly> LoadAssemblies(
 32        bool continueOnAssemblyError)
 33    {
 29334        var sourceAssemblies = _directories
 29335            .SelectMany(Directory.GetFiles)
 29336            .Where(x =>
 29337            {
 1800738                var fileName = Path.GetFileName(x);
 1800739                return _fileFilter.Invoke(fileName);
 29340            })
 29341            .Select(p =>
 29342            {
 29343                try
 29344                {
 59045                    return Assembly.LoadFrom(p);
 29346                }
 147                catch (Exception ex)
 29348                {
 149                    if (continueOnAssemblyError)
 29350                    {
 051                        return null;
 29352                    }
 29353                    else
 29354                    {
 155                        throw new InvalidOperationException($"Failed to load assembly from path: {p}", ex);
 29356                    }
 29357                }
 58958            })
 58959            .Where(x => x != null)
 29360            .Cast<Assembly>()
 29361            .ToArray();
 29162        return sourceAssemblies;
 63    }
 64}