namespace HeuristicLab.Problems.ProgramSynthesis.Push.Expressions { using System; public abstract class StatefullExpression : Expression { public readonly T State; private readonly Lazy hashCode; protected StatefullExpression(T state) { this.State = state; this.hashCode = new Lazy(this.CalcHashCode, true); } protected virtual int CalcHashCode() { return this.State.GetHashCode(); } public override bool Equals(object obj) { if (ReferenceEquals(this, obj)) return true; if (this.GetType() != obj.GetType()) return false; var other = (StatefullExpression)obj; return ReferenceEquals(this.State, other.State) || this.GetHashCode() == other.GetHashCode(); } public override int GetHashCode() { return this.hashCode.Value; } } }