Skip to content

Instantly share code, notes, and snippets.

@RolandPheasant
Created October 17, 2020 08:00
Show Gist options
  • Save RolandPheasant/7bda54a5cc37df248e9ddf780d14d2c3 to your computer and use it in GitHub Desktop.
Save RolandPheasant/7bda54a5cc37df248e9ddf780d14d2c3 to your computer and use it in GitHub Desktop.
Hashcode
using System;
using System.Collections.Generic;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;
namespace WpfApp1
{
public class TestViewModel : ReactiveObject, IEquatable<TestViewModel>
{
public TestViewModel(int ModelId, bool IsArchived)
{
this.ModelId = ModelId;
this.IsArchived = IsArchived;
this.DisplayName = $"Item #{ModelId}";
}
public int ModelId { get; }
[Reactive] public string DisplayName { get; set; }
[Reactive] public bool IsArchived { get; set; }
public override bool Equals(object obj) => Equals(obj as TestViewModel);
public bool Equals(TestViewModel other) => other != null && ModelId == other.ModelId;
public override int GetHashCode() => HashCode.Combine(ModelId);
public static bool operator ==(TestViewModel left, TestViewModel right) => EqualityComparer<TestViewModel>.Default.Equals(left, right);
public static bool operator !=(TestViewModel left, TestViewModel right) => !(left == right);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment