// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Linq; using CommunityToolkit.Mvvm.SourceGenerators.Extensions; using CommunityToolkit.Mvvm.SourceGenerators.Helpers; namespace CommunityToolkit.Mvvm.SourceGenerators.ComponentModel.Models; /// /// A model representing an generated property /// /// The type name for the generated property, including nullability annotations. /// The field name. /// The generated property name. /// The sequence of property changing properties to notify. /// The sequence of property changed properties to notify. /// The sequence of commands to notify. /// Whether or not the generated property also broadcasts changes. /// The sequence of validation attributes for the generated property. internal sealed record PropertyInfo( string TypeNameWithNullabilityAnnotations, string FieldName, string PropertyName, ImmutableArray PropertyChangingNames, ImmutableArray PropertyChangedNames, ImmutableArray NotifiedCommandNames, bool AlsoBroadcastChange, ImmutableArray ValidationAttributes) { /// /// An implementation for . /// public sealed class Comparer : Comparer { /// protected override void AddToHashCode(ref HashCode hashCode, PropertyInfo obj) { hashCode.Add(obj.TypeNameWithNullabilityAnnotations); hashCode.Add(obj.FieldName); hashCode.Add(obj.PropertyName); hashCode.AddRange(obj.PropertyChangingNames); hashCode.AddRange(obj.PropertyChangedNames); hashCode.AddRange(obj.NotifiedCommandNames); hashCode.Add(obj.AlsoBroadcastChange); hashCode.AddRange(obj.ValidationAttributes, AttributeInfo.Comparer.Default); } /// protected override bool AreEqual(PropertyInfo x, PropertyInfo y) { return x.TypeNameWithNullabilityAnnotations == y.TypeNameWithNullabilityAnnotations && x.FieldName == y.FieldName && x.PropertyName == y.PropertyName && x.PropertyChangingNames.SequenceEqual(y.PropertyChangingNames) && x.PropertyChangedNames.SequenceEqual(y.PropertyChangedNames) && x.NotifiedCommandNames.SequenceEqual(y.NotifiedCommandNames) && x.AlsoBroadcastChange == y.AlsoBroadcastChange && x.ValidationAttributes.SequenceEqual(y.ValidationAttributes, AttributeInfo.Comparer.Default); } } }