Ensure the equality checks for our ViewModels use the underlying Model object so even if we create a new wrapper we'll compare it against what it actually contains.

This commit is contained in:
Michael Hawker
2024-12-11 12:03:56 -08:00
parent 7580872e82
commit f176b0d058
2 changed files with 8 additions and 0 deletions

View File

@@ -107,4 +107,8 @@ public partial class ListItemViewModel(IListItem model, TaskScheduler scheduler)
public bool MatchesFilter(string filter) => StringMatcher.FuzzySearch(filter, Title).Success || StringMatcher.FuzzySearch(filter, Subtitle).Success;
public override string ToString() => $"{Name} ListItemViewModel";
public override bool Equals(object? obj) => obj is ListItemViewModel vm && vm._listItemModel.Equals(this._listItemModel);
public override int GetHashCode() => _listItemModel.GetHashCode();
}

View File

@@ -7,4 +7,8 @@ namespace Microsoft.CmdPal.UI.ViewModels.Models;
public class ExtensionObject<T>(T? value) // where T : IInspectable
{
public T? Unsafe { get; } = value;
public override bool Equals(object? obj) => obj is ExtensionObject<T> ext && ext.Unsafe?.Equals(this.Unsafe) == true;
public override int GetHashCode() => Unsafe?.GetHashCode() ?? base.GetHashCode();
}