< Summary

Information
Class: NexusLabs.Needlr.Generators.GenerateTypeRegistryAttribute
Assembly: NexusLabs.Needlr.Generators.Attributes
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators.Attributes/GenerateTypeRegistryAttribute.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 79
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_IncludeNamespacePrefixes()100%11100%
get_ExcludeNamespacePrefixes()100%11100%
get_IncludeSelf()100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators.Attributes/GenerateTypeRegistryAttribute.cs

#LineLine coverage
 1using System;
 2
 3namespace NexusLabs.Needlr.Generators;
 4
 5/// <summary>
 6/// Marks an assembly for compile-time type registry generation.
 7/// The source generator will scan all referenced assemblies and generate
 8/// a TypeRegistry class containing all injectable types.
 9/// </summary>
 10/// <remarks>
 11/// <para>
 12/// This attribute triggers the source generator to analyze all types
 13/// in referenced assemblies at compile time, eliminating the need for
 14/// runtime reflection-based type discovery.
 15/// </para>
 16/// <para>
 17/// Use <see cref="IncludeNamespacePrefixes"/> to filter which types
 18/// are included in the generated registry. This is similar to the
 19/// <c>MatchingAssemblies()</c> method in the reflection-based approach.
 20/// </para>
 21/// </remarks>
 22/// <example>
 23/// <code>
 24/// // Include all types from NexusLabs and MyCompany namespaces
 25/// [assembly: GenerateTypeRegistry(IncludeNamespacePrefixes = new[] { "NexusLabs", "MyCompany" })]
 26/// </code>
 27/// </example>
 28[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
 29public sealed class GenerateTypeRegistryAttribute : Attribute
 30{
 31    /// <summary>
 32    /// Gets or sets namespace prefix filters. Only types in namespaces starting with
 33    /// these prefixes will be included in the generated registry.
 34    /// </summary>
 35    /// <remarks>
 36    /// This is analogous to the <c>MatchingAssemblies()</c> configuration in the
 37    /// reflection-based approach. If null or empty, all namespaces are included.
 38    /// When both <see cref="IncludeNamespacePrefixes"/> and <see cref="ExcludeNamespacePrefixes"/>
 39    /// are set, inclusion runs first, then exclusion filters out matches.
 40    /// </remarks>
 541    public string[]? IncludeNamespacePrefixes { get; set; }
 42
 43    /// <summary>
 44    /// Gets or sets namespace prefixes to exclude from the generated registry.
 45    /// Types whose namespace starts with any of these prefixes will be skipped,
 46    /// even if they match <see cref="IncludeNamespacePrefixes"/>.
 47    /// </summary>
 48    /// <remarks>
 49    /// <para>
 50    /// Use this to prevent scanning framework types from libraries like Avalonia, MAUI,
 51    /// or other UI frameworks that expose many public types Needlr would otherwise try
 52    /// to register. Exclusion is applied after inclusion — if a type matches both an
 53    /// include prefix and an exclude prefix, it is excluded.
 54    /// </para>
 55    /// </remarks>
 56    /// <example>
 57    /// <code>
 58    /// // Include MyApp types but exclude Avalonia framework types
 59    /// [assembly: GenerateTypeRegistry(
 60    ///     IncludeNamespacePrefixes = new[] { "MyApp" },
 61    ///     ExcludeNamespacePrefixes = new[] { "Avalonia" })]
 62    ///
 63    /// // Include everything except Avalonia
 64    /// [assembly: GenerateTypeRegistry(
 65    ///     ExcludeNamespacePrefixes = new[] { "Avalonia" })]
 66    /// </code>
 67    /// </example>
 568    public string[]? ExcludeNamespacePrefixes { get; set; }
 69
 70    /// <summary>
 71    /// Gets or sets whether to include types from the current assembly
 72    /// in addition to referenced assemblies.
 73    /// </summary>
 74    /// <remarks>
 75    /// Defaults to <c>true</c>. Set to <c>false</c> to only include types
 76    /// from project references.
 77    /// </remarks>
 1078    public bool IncludeSelf { get; set; } = true;
 79}