using System; using System.Collections.Generic; using System.Runtime.CompilerServices; using Unity.UIWidgets.foundation; namespace UIWidgetsSample { public abstract class Equatable : IEquatable { /// {@macro equatable} public Equatable() { } /// {@template equatable_props} /// The list of properties that will be used to determine whether /// two instances are equal. /// {@endtemplate} public abstract List props { get; } /// {@template equatable_stringify} /// If set to `true`, the [toString] method will be overridden to output /// this instance's [props]. /// /// A global default value for [stringify] can be set using /// `EquatableConfig.stringify`. /// /// If this instance's [stringify] is set to null, the value of /// `EquatableConfig.stringify` will be used instead. This defaults to /// `false`. /// {@endtemplate} // ignore: avoid_returning_null bool? stringify { get { return null; } } public static bool operator ==(Equatable left,Equatable right) { return left is Equatable && Equals(left, right) && Equals(left.props,right.props); } public static bool operator !=(Equatable left, Equatable right) { return !(left == right); } /* public override int GetHashCode() { return (this.GetType().GetHashCode()) ^ mapPropsToHashCode(props); }*/ // ???? public override string ToString() { switch (stringify) { case true: return EquatableUtils.mapPropsToString(this.GetType(), props); case false: return this.GetType().ToString(); default: return EquatableConfig.stringify == true ? EquatableUtils.mapPropsToString(this.GetType(), props) : this.GetType().ToString(); } } public bool Equals(Equatable other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(props, other.props); } public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (obj.GetType() != this.GetType()) return false; return Equals((Equatable) obj); } public override int GetHashCode() { return (props != null ? props.GetHashCode() : 0); } } }