| | | 1 | | using System; |
| | | 2 | | |
| | | 3 | | namespace NexusLabs.Needlr.Generators.Models; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// The stable, scalar emission context shared by every generated-constructor model in |
| | | 7 | | /// the compilation: the current assembly name and the configured breadcrumb verbosity. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// Deliberately holds only cheap, independently-cacheable scalar values rather than the |
| | | 11 | | /// <see cref="Microsoft.CodeAnalysis.Compilation"/> or |
| | | 12 | | /// <see cref="Microsoft.CodeAnalysis.Diagnostics.AnalyzerConfigOptionsProvider"/> objects |
| | | 13 | | /// they were derived from. Combining a per-type model with the entire |
| | | 14 | | /// <c>Compilation</c> would invalidate every generated constructor whenever anything in |
| | | 15 | | /// the compilation changed (the exact bug this model exists to avoid); combining with |
| | | 16 | | /// this instead lets the incremental pipeline reuse a cached emission context across |
| | | 17 | | /// edits that don't touch the assembly name or breadcrumb MSBuild property. |
| | | 18 | | /// </remarks> |
| | | 19 | | internal readonly struct GeneratedConstructorEmitContext : IEquatable<GeneratedConstructorEmitContext> |
| | | 20 | | { |
| | | 21 | | public GeneratedConstructorEmitContext(string assemblyName, BreadcrumbLevel breadcrumbLevel) |
| | | 22 | | { |
| | 67 | 23 | | AssemblyName = assemblyName; |
| | 67 | 24 | | BreadcrumbLevel = breadcrumbLevel; |
| | 67 | 25 | | } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// The current compilation's assembly name, or <c>"Generated"</c> as a fallback. |
| | | 29 | | /// </summary> |
| | 76 | 30 | | public string AssemblyName { get; } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// The configured breadcrumb verbosity, read from the |
| | | 34 | | /// <c>NeedlrBreadcrumbLevel</c> MSBuild property. |
| | | 35 | | /// </summary> |
| | 76 | 36 | | public BreadcrumbLevel BreadcrumbLevel { get; } |
| | | 37 | | |
| | | 38 | | public bool Equals(GeneratedConstructorEmitContext other) |
| | | 39 | | { |
| | 5 | 40 | | return string.Equals(AssemblyName, other.AssemblyName, StringComparison.Ordinal) && |
| | 5 | 41 | | BreadcrumbLevel == other.BreadcrumbLevel; |
| | | 42 | | } |
| | | 43 | | |
| | 0 | 44 | | public override bool Equals(object? obj) => obj is GeneratedConstructorEmitContext other && Equals(other); |
| | | 45 | | |
| | | 46 | | public override int GetHashCode() |
| | | 47 | | { |
| | | 48 | | unchecked |
| | | 49 | | { |
| | 0 | 50 | | return (AssemblyName.GetHashCode() * 397) ^ (int)BreadcrumbLevel; |
| | | 51 | | } |
| | | 52 | | } |
| | | 53 | | |
| | 0 | 54 | | public static bool operator ==(GeneratedConstructorEmitContext left, GeneratedConstructorEmitContext right) => left. |
| | | 55 | | |
| | 0 | 56 | | public static bool operator !=(GeneratedConstructorEmitContext left, GeneratedConstructorEmitContext right) => !left |
| | | 57 | | } |