Enable generator support for defaulted fields

このコミットが含まれているのは:
Sergio Pedri committed 2022-08-08 15:45:44 +02:00
1 親 5a93bc23eb
コミット 4f6d94cc8f
4ファイル変更
+84 -19

検索条件に一致するファイルはありません

+36
ファイルの表示
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using ComputeSharp.SourceGeneration.Extensions;
using ComputeSharp.SourceGeneration.Helpers;
namespace ComputeSharp.Core.SourceGenerators.Models;
/// <summary>
/// A model containiing information on a constructor to generate.
/// </summary>
/// <param name="Parameters">The <see cref="ParameterInfo"/> values for the constructor.</param>
/// <param name="DefaultedFields">The names of ignored fields that should be defaulted.</param>
internal sealed record ConstructorInfo(ImmutableArray<ParameterInfo> Parameters, ImmutableArray<string> DefaultedFields)
{
/// <summary>
/// An <see cref="IEqualityComparer{T}"/> implementation for <see cref="ConstructorInfo"/>.
/// </summary>
public sealed class Comparer : Comparer<ConstructorInfo, Comparer>
{
/// <inheritdoc/>
protected override void AddToHashCode(ref HashCode hashCode, ConstructorInfo obj)
{
hashCode.AddRange(obj.Parameters);
hashCode.AddRange(obj.DefaultedFields);
}
/// <inheritdoc/>
protected override bool AreEqual(ConstructorInfo x, ConstructorInfo y)
{
return
x.Parameters.SequenceEqual(y.Parameters) &&
x.DefaultedFields.SequenceEqual(y.DefaultedFields);
}
}
}