< Summary

Information
Class: NexusLabs.Needlr.Generators.Models.DiscoveredOptions
Assembly: NexusLabs.Needlr.Generators
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators/Models/Options/DiscoveredOptions.cs
Line coverage
96%
Covered lines: 31
Uncovered lines: 1
Coverable lines: 32
Total lines: 94
Line coverage: 96.8%
Branch coverage
62%
Covered branches: 5
Total branches: 8
Branch coverage: 62.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators/Models/Options/DiscoveredOptions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4
 5namespace NexusLabs.Needlr.Generators.Models;
 6
 7/// <summary>
 8/// Information about a discovered options type (from [Options]).
 9/// </summary>
 10internal readonly struct DiscoveredOptions
 11{
 12    public DiscoveredOptions(
 13        string typeName,
 14        string sectionName,
 15        string? name,
 16        bool validateOnStart,
 17        string assemblyName,
 18        string? sourceFilePath = null,
 19        OptionsValidatorInfo? validatorMethod = null,
 20        string? validateMethodOverride = null,
 21        string? validatorTypeName = null,
 22        PositionalRecordInfo? positionalRecordInfo = null,
 23        IReadOnlyList<OptionsPropertyInfo>? properties = null)
 24    {
 17325        TypeName = typeName;
 17326        SectionName = sectionName;
 17327        Name = name;
 17328        ValidateOnStart = validateOnStart;
 17329        AssemblyName = assemblyName;
 17330        SourceFilePath = sourceFilePath;
 17331        ValidatorMethod = validatorMethod;
 17332        ValidateMethodOverride = validateMethodOverride;
 17333        ValidatorTypeName = validatorTypeName;
 17334        PositionalRecordInfo = positionalRecordInfo;
 17335        Properties = properties ?? Array.Empty<OptionsPropertyInfo>();
 17336    }
 37
 38    /// <summary>Fully qualified type name of the options class.</summary>
 100639    public string TypeName { get; }
 40
 41    /// <summary>Configuration section name (e.g., "Database").</summary>
 45642    public string SectionName { get; }
 43
 44    /// <summary>Named options name (e.g., "Primary"), or null for default options.</summary>
 40345    public string? Name { get; }
 46
 47    /// <summary>Whether to validate options on startup.</summary>
 45748    public bool ValidateOnStart { get; }
 49
 16550    public string AssemblyName { get; }
 19151    public string? SourceFilePath { get; }
 52
 53    /// <summary>Information about the validation method (discovered or specified).</summary>
 50954    public OptionsValidatorInfo? ValidatorMethod { get; }
 55
 56    /// <summary>Custom validation method name override from [Options(ValidateMethod = "...")], or null to use conventio
 2257    public string? ValidateMethodOverride { get; }
 58
 59    /// <summary>External validator type name from [Options(Validator = typeof(...))], or null to use options class.</su
 14860    public string? ValidatorTypeName { get; }
 61
 62    /// <summary>Information about positional record primary constructor, if applicable.</summary>
 45263    public PositionalRecordInfo? PositionalRecordInfo { get; }
 64
 65    /// <summary>Bindable properties for AOT code generation.</summary>
 65366    public IReadOnlyList<OptionsPropertyInfo> Properties { get; }
 67
 68    /// <summary>True if this is a named options registration (not default).</summary>
 19269    public bool IsNamed => Name != null;
 70
 71    /// <summary>True if this options type has a custom validator method.</summary>
 42972    public bool HasValidatorMethod => ValidatorMethod != null;
 73
 74    /// <summary>True if an external validator type is specified.</summary>
 13875    public bool HasExternalValidator => ValidatorTypeName != null;
 76
 77    /// <summary>True if this is a positional record that needs a generated parameterless constructor.</summary>
 16578    public bool NeedsGeneratedConstructor => PositionalRecordInfo?.IsPartial == true;
 79
 80    /// <summary>True if this is a non-partial positional record (will emit diagnostic).</summary>
 16581    public bool IsNonPartialPositionalRecord => PositionalRecordInfo != null && !PositionalRecordInfo.Value.IsPartial;
 82
 83    /// <summary>True if this type has any init-only properties (requires factory pattern in AOT).</summary>
 20984    public bool HasInitOnlyProperties => Properties.Any(p => p.HasInitOnlySetter);
 85
 86    /// <summary>True if this is a positional record (uses constructor binding in AOT).</summary>
 8787    public bool IsPositionalRecord => PositionalRecordInfo != null;
 88
 89    /// <summary>True if this type requires factory pattern (Options.Create) instead of Configure delegate in AOT.</summ
 090    public bool RequiresFactoryPattern => IsPositionalRecord || HasInitOnlyProperties;
 91
 92    /// <summary>True if any property has DataAnnotation validation attributes.</summary>
 108993    public bool HasDataAnnotations => Properties.Any(p => p.HasDataAnnotations);
 94}