• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

loresoft / KickStart / 17529667504

07 Sep 2025 02:14PM UTC coverage: 60.921%. Remained the same
17529667504

push

github

pwelter34
reformat code base

162 of 364 branches covered (44.51%)

Branch coverage included in aggregate %.

634 of 951 new or added lines in 72 files covered. (66.67%)

4 existing lines in 4 files now uncovered.

658 of 982 relevant lines covered (67.01%)

20.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.48
/src/KickStart/AssemblyResolver.cs
1
using System.Reflection;
2

3
#if PORTABLE
4
using Stopwatch = KickStart.Portability.Stopwatch;
5
#else
6
using Stopwatch = System.Diagnostics.Stopwatch;
7
#endif
8

9
namespace KickStart;
10

11
/// <summary>
12
/// A class to resolve assemblies for scanning.
13
/// </summary>
14
public class AssemblyResolver
15
{
16
    private readonly List<Func<IEnumerable<Assembly>>> _sources;
17
    private readonly List<Func<Assembly, bool>> _includes;
18
    private readonly List<Func<Assembly, bool>> _excludes;
19
    private readonly Action<string> _logWriter;
20

21
    /// <summary>
22
    /// Initializes a new instance of the <see cref="AssemblyResolver"/> class.
23
    /// </summary>
24
    /// <param name="logWriter">A function to write log messages to.</param>
25
    public AssemblyResolver(Action<string> logWriter = null)
27✔
26
    {
27
        _sources = new List<Func<IEnumerable<Assembly>>>();
27✔
28
        _includes = new List<Func<Assembly, bool>>();
27✔
29
        _excludes = new List<Func<Assembly, bool>>();
27✔
30
        _logWriter = logWriter;
27✔
31
    }
27✔
32

33
    /// <summary>
34
    /// Gets the assembly sources.
35
    /// </summary>
36
    /// <value>
37
    /// The assembly sources.
38
    /// </value>
39
    public List<Func<IEnumerable<Assembly>>> Sources
40
    {
41
        get { return _sources; }
27✔
42
    }
43

44
    /// <summary>
45
    /// Gets the include rules.
46
    /// </summary>
47
    /// <value>
48
    /// The include rules.
49
    /// </value>
50
    public List<Func<Assembly, bool>> Includes
51
    {
52
        get { return _includes; }
27✔
53
    }
54

55
    /// <summary>
56
    /// Gets the exclude rules.
57
    /// </summary>
58
    /// <value>
59
    /// The exclude rules.
60
    /// </value>
61
    public List<Func<Assembly, bool>> Excludes
62
    {
63
        get { return _excludes; }
27✔
64
    }
65

66

67
    /// <summary>
68
    /// Include the current loaded assemblies as a source.
69
    /// </summary>
70
    public void IncludeLoadedAssemblies()
71
    {
72
#if PORTABLE || NETSTANDARD1_3 || NETSTANDARD1_5 || NETSTANDARD1_6
73
        //TDOD figure out how to do this
74
#else
75
        _sources.Add(() => AppDomain.CurrentDomain.GetAssemblies());
4✔
76
#endif
77
    }
2✔
78

79
    /// <summary>
80
    /// Include the assembly from the specified type <typeparamref name="T"/>.
81
    /// </summary>
82
    /// <typeparam name="T">The type to get assembly from.</typeparam>
83
    public void IncludeAssemblyFor<T>()
84
    {
85
        IncludeAssembly(typeof(T).GetTypeInfo().Assembly);
11✔
86
    }
11✔
87

88
    /// <summary>
89
    /// Include the specified <see cref="Assembly"/>.
90
    /// </summary>
91
    /// <param name="assembly">The assembly to include.</param>
92
    public void IncludeAssembly(Assembly assembly)
93
    {
94
        _sources.Add(() => new[] { assembly });
76✔
95
    }
38✔
96

97
    /// <summary>
98
    /// Include the assemblies that contain the specified name.
99
    /// </summary>
100
    /// <param name="name">The name to compare.</param>
101
    public void IncludeName(string name)
102
    {
NEW
103
        _includes.Add(a => a.FullName.Contains(name));
×
NEW
104
    }
×
105

106

107
    /// <summary>
108
    /// Exclude the assembly from the specified type <typeparamref name="T"/>.
109
    /// </summary>
110
    /// <typeparam name="T">The type to get assembly from.</typeparam>
111
    public void ExcludeAssemblyFor<T>()
112
    {
113
        ExcludeAssembly(typeof(T).GetTypeInfo().Assembly);
22✔
114
    }
22✔
115

116
    /// <summary>
117
    /// Exclude the specified <see cref="Assembly"/>.
118
    /// </summary>
119
    /// <param name="assembly">The assembly to exclude.</param>
120
    public void ExcludeAssembly(Assembly assembly)
121
    {
122
        _excludes.Add(a => a == assembly);
133✔
123
    }
60✔
124

125
    /// <summary>
126
    /// Exclude the assemblies that start with the specified <paramref name="name"/>.
127
    /// </summary>
128
    /// <param name="name">The name to compare.</param>
129
    public void ExcludeName(string name)
130
    {
131
        _excludes.Add(a => a.FullName.StartsWith(name));
228✔
132
    }
68✔
133

134

135
    /// <summary>
136
    /// Resolves a list of assemblies using the <see cref="Sources"/>, <see cref="Includes"/>, and <see cref="Excludes"/> rules.
137
    /// </summary>
138
    /// <returns>An enumberable list of assemblies.</returns>
139
    public IEnumerable<Assembly> Resolve()
140
    {
141
        // default to loaded assemblies
142
        if (_sources.Count == 0)
27✔
143
            IncludeLoadedAssemblies();
2✔
144

145
        _logWriter?.Invoke($"Assembly Resolver Start; Sources: ({Sources.Count}), Includes: ({Includes.Count}), Excludes: ({Excludes.Count})");
27!
146

147

148
        var watch = Stopwatch.StartNew();
27✔
149

150
        var assemblies = _sources
27✔
151
            .SelectMany(source => source())
40✔
152
            .Where(assembly => _includes.Count == 0 || _includes.Any(include => include(assembly)))
186✔
153
            .Where(assembly => _excludes.Count == 0 || !_excludes.Any(exclude => exclude(assembly)))
419✔
154
            .Distinct()
27✔
155
            .ToList();
27✔
156

157
        watch.Stop();
27✔
158

159
        _logWriter?.Invoke($"Assembly Resolver Complete; Assemblies: ({assemblies.Count}), Time: {watch.ElapsedMilliseconds} ms");
27!
160

161
        return assemblies;
27✔
162
    }
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc