< 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
75%
Covered branches: 6
Total branches: 8
Branch coverage: 75%
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    {
 20425        TypeName = typeName;
 20426        SectionName = sectionName;
 20427        Name = name;
 20428        ValidateOnStart = validateOnStart;
 20429        AssemblyName = assemblyName;
 20430        SourceFilePath = sourceFilePath;
 20431        ValidatorMethod = validatorMethod;
 20432        ValidateMethodOverride = validateMethodOverride;
 20433        ValidatorTypeName = validatorTypeName;
 20434        PositionalRecordInfo = positionalRecordInfo;
 20435        Properties = properties ?? Array.Empty<OptionsPropertyInfo>();
 20436    }
 37
 38    /// <summary>Fully qualified type name of the options class.</summary>
 113139    public string TypeName { get; }
 40
 41    /// <summary>Configuration section name (e.g., "Database").</summary>
 53342    public string SectionName { get; }
 43
 44    /// <summary>Named options name (e.g., "Primary"), or null for default options.</summary>
 48845    public string? Name { get; }
 46
 47    /// <summary>Whether to validate options on startup.</summary>
 53948    public bool ValidateOnStart { get; }
 49
 17450    public string AssemblyName { get; }
 21651    public string? SourceFilePath { get; }
 52
 53    /// <summary>Information about the validation method (discovered or specified).</summary>
 61354    public OptionsValidatorInfo? ValidatorMethod { get; }
 55
 56    /// <summary>Custom validation method name override from [Options(ValidateMethod = "...")], or null to use conventio
 4957    public string? ValidateMethodOverride { get; }
 58
 59    /// <summary>External validator type name from [Options(Validator = typeof(...))], or null to use options class.</su
 24160    public string? ValidatorTypeName { get; }
 61
 62    /// <summary>Information about positional record primary constructor, if applicable.</summary>
 49863    public PositionalRecordInfo? PositionalRecordInfo { get; }
 64
 65    /// <summary>Bindable properties for AOT code generation.</summary>
 67566    public IReadOnlyList<OptionsPropertyInfo> Properties { get; }
 67
 68    /// <summary>True if this is a named options registration (not default).</summary>
 25169    public bool IsNamed => Name != null;
 70
 71    /// <summary>True if this options type has a custom validator method.</summary>
 49572    public bool HasValidatorMethod => ValidatorMethod != null;
 73
 74    /// <summary>True if an external validator type is specified.</summary>
 21775    public bool HasExternalValidator => ValidatorTypeName != null;
 76
 77    /// <summary>True if this is a positional record that needs a generated parameterless constructor.</summary>
 17478    public bool NeedsGeneratedConstructor => PositionalRecordInfo?.IsPartial == true;
 79
 80    /// <summary>True if this is a non-partial positional record (will emit diagnostic).</summary>
 17481    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>
 9187    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>
 127193    public bool HasDataAnnotations => Properties.Any(p => p.HasDataAnnotations);
 94}