< Summary

Information
Class: NexusLabs.Needlr.Generators.Models.ConstructorGuardModel
Assembly: NexusLabs.Needlr.Generators
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators/Models/Constructors/ConstructorGuardModel.cs
Line coverage
100%
Covered lines: 27
Uncovered lines: 0
Coverable lines: 27
Total lines: 95
Line coverage: 100%
Branch coverage
85%
Covered branches: 17
Total branches: 20
Branch coverage: 85%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
get_Kind()100%11100%
get_CustomGuardTypeName()100%11100%
get_CustomGuardMethodName()100%11100%
get_ForwardedArgumentLiterals()100%11100%
Equals(...)100%66100%
Equals(...)50%22100%
GetHashCode()66.66%66100%
op_Equality(...)100%11100%
op_Inequality(...)100%11100%
ForwardedArgumentLiteralsEqual(...)100%44100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.Generators/Models/Constructors/ConstructorGuardModel.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3
 4namespace NexusLabs.Needlr.Generators.Models;
 5
 6/// <summary>
 7/// A normalized constructor guard to emit for a generated-constructor parameter,
 8/// either a built-in kind or a resolved custom guard type and method call.
 9/// </summary>
 10/// <remarks>
 11/// Implements value equality so generated-constructor and record-overload models that
 12/// contain arrays of guards remain cacheable across incremental generator runs.
 13/// Positional literals forwarded from a parameterized alias are compared
 14/// element-by-element rather than by array reference.
 15/// </remarks>
 16internal readonly struct ConstructorGuardModel : IEquatable<ConstructorGuardModel>
 17{
 18    public ConstructorGuardModel(
 19        GeneratedConstructorGuardKind kind,
 20        string? customGuardTypeName,
 21        string? customGuardMethodName,
 22        string[]? forwardedArgumentLiterals)
 23    {
 15524        Kind = kind;
 15525        CustomGuardTypeName = customGuardTypeName;
 15526        CustomGuardMethodName = customGuardMethodName;
 15527        ForwardedArgumentLiterals = forwardedArgumentLiterals ?? Array.Empty<string>();
 15528    }
 29
 30    /// <summary>
 31    /// The guard kind. <see cref="GeneratedConstructorGuardKind.Custom"/> indicates a
 32    /// resolved custom guard type and method call.
 33    /// </summary>
 48234    public GeneratedConstructorGuardKind Kind { get; }
 35
 36    /// <summary>
 37    /// The fully qualified custom guard type name, or <see langword="null"/> for a
 38    /// built-in guard.
 39    /// </summary>
 23140    public string? CustomGuardTypeName { get; }
 41
 42    /// <summary>
 43    /// The resolved custom guard method name, or <see langword="null"/> for a built-in
 44    /// guard.
 45    /// </summary>
 22946    public string? CustomGuardMethodName { get; }
 47
 48    /// <summary>
 49    /// Rendered C# literals forwarded from a parameterized alias attribute usage, in
 50    /// declared order.
 51    /// </summary>
 23652    public string[] ForwardedArgumentLiterals { get; }
 53
 54    public bool Equals(ConstructorGuardModel other)
 55    {
 5856        return Kind == other.Kind &&
 5857            string.Equals(CustomGuardTypeName, other.CustomGuardTypeName, StringComparison.Ordinal) &&
 5858            string.Equals(CustomGuardMethodName, other.CustomGuardMethodName, StringComparison.Ordinal) &&
 5859            ForwardedArgumentLiteralsEqual(ForwardedArgumentLiterals, other.ForwardedArgumentLiterals);
 60    }
 61
 262    public override bool Equals(object? obj) => obj is ConstructorGuardModel other && Equals(other);
 63
 64    public override int GetHashCode()
 65    {
 66        unchecked
 67        {
 2068            var hash = (int)Kind;
 2069            hash = (hash * 397) ^ (CustomGuardTypeName?.GetHashCode() ?? 0);
 2070            hash = (hash * 397) ^ (CustomGuardMethodName?.GetHashCode() ?? 0);
 71
 10472            foreach (var literal in ForwardedArgumentLiterals)
 73            {
 3274                hash = (hash * 397) ^ literal.GetHashCode();
 75            }
 76
 2077            return hash;
 78        }
 79    }
 80
 181    public static bool operator ==(ConstructorGuardModel left, ConstructorGuardModel right) => left.Equals(right);
 82
 183    public static bool operator !=(ConstructorGuardModel left, ConstructorGuardModel right) => !left.Equals(right);
 84
 85    private static bool ForwardedArgumentLiteralsEqual(string[] left, string[] right)
 86    {
 4187        if (ReferenceEquals(left, right))
 288            return true;
 89
 3990        if (left.Length != right.Length)
 191            return false;
 92
 3893        return left.SequenceEqual(right, StringComparer.Ordinal);
 94    }
 95}