// 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.Input.Models;
///
/// A model with gathered info on a given command method.
///
/// The name of the target method.
/// The resulting field name for the generated command.
/// The resulting property name for the generated command.
/// The command interface type name.
/// The command class type name.
/// The delegate type name for the wrapped method.
/// The type arguments for and , if any.
/// The type arguments for , if any.
/// The member name for the can execute check, if available.
/// The can execute expression type, if available.
/// Whether or not concurrent executions have been enabled.
/// Whether or not to also generate a cancel command.
internal sealed record CommandInfo(
string MethodName,
string FieldName,
string PropertyName,
string CommandInterfaceType,
string CommandClassType,
string DelegateType,
ImmutableArray CommandTypeArguments,
ImmutableArray DelegateTypeArguments,
string? CanExecuteMemberName,
CanExecuteExpressionType? CanExecuteExpressionType,
bool AllowConcurrentExecutions,
bool IncludeCancelCommand)
{
///
/// An implementation for .
///
public sealed class Comparer : Comparer
{
///
protected override void AddToHashCode(ref HashCode hashCode, CommandInfo obj)
{
hashCode.Add(obj.MethodName);
hashCode.Add(obj.FieldName);
hashCode.Add(obj.PropertyName);
hashCode.Add(obj.CommandInterfaceType);
hashCode.Add(obj.CommandClassType);
hashCode.Add(obj.DelegateType);
hashCode.AddRange(obj.CommandTypeArguments);
hashCode.AddRange(obj.DelegateTypeArguments);
hashCode.Add(obj.CanExecuteMemberName);
hashCode.Add(obj.CanExecuteExpressionType);
hashCode.Add(obj.AllowConcurrentExecutions);
hashCode.Add(obj.IncludeCancelCommand);
}
///
protected override bool AreEqual(CommandInfo x, CommandInfo y)
{
return
x.MethodName == y.MethodName &&
x.FieldName == y.FieldName &&
x.PropertyName == y.PropertyName &&
x.CommandInterfaceType == y.CommandInterfaceType &&
x.CommandClassType == y.CommandClassType &&
x.DelegateType == y.DelegateType &&
x.CommandTypeArguments.SequenceEqual(y.CommandTypeArguments) &&
x.DelegateTypeArguments.SequenceEqual(y.CommandTypeArguments) &&
x.CanExecuteMemberName == y.CanExecuteMemberName &&
x.CanExecuteExpressionType == y.CanExecuteExpressionType &&
x.AllowConcurrentExecutions == y.AllowConcurrentExecutions &&
x.IncludeCancelCommand == y.IncludeCancelCommand;
}
}
}