using System; using System.Collections.Generic; using System.Linq; using ComputeSharp.SourceGenerators.Extensions; using Microsoft.CodeAnalysis; namespace ComputeSharp.SourceGenerators.Models; /// /// A model for a serializeable diagnostic provider. /// /// The wrapped instance. /// The diagnostic args. internal sealed record DiagnosticInfo(DiagnosticDescriptor Descriptor, params object[] Args) { /// /// An implementation for . /// public sealed class Comparer : IEqualityComparer { /// /// The singleton instance. /// public static Comparer Default { get; } = new(); /// public bool Equals(DiagnosticInfo? x, DiagnosticInfo? y) { if (x is null && y is null) { return true; } if (x is null || y is null) { return false; } if (ReferenceEquals(x, y)) { return true; } return x.Descriptor.Equals(y.Descriptor) && x.Args.SequenceEqual(y.Args); } /// public int GetHashCode(DiagnosticInfo obj) { HashCode hashCode = default; hashCode.Add(obj.Descriptor); foreach (object arg in obj.Args) { hashCode.Add(arg); } return hashCode.ToHashCode(); } } }