using System.Collections.Generic; namespace OpenAuth.Domain.Utility { public abstract class EntityBase { private List _brokenRules = new List(); public TId Id { get; set; } protected abstract void Validate(); public IEnumerable GetBrokenRules() { _brokenRules.Clear(); Validate(); return _brokenRules; } protected void AddBrokenRule(BusinessRule businessRule) { _brokenRules.Add(businessRule); } public override bool Equals(object entity) { return entity != null && entity is EntityBase && this == (EntityBase)entity; } public override int GetHashCode() { return this.Id.GetHashCode(); } public static bool operator ==(EntityBase entity1, EntityBase entity2) { if ((object)entity1 == null && (object)entity2 == null) { return true; } if ((object)entity1 == null || (object)entity2 == null) { return false; } if (entity1.Id.ToString() == entity2.Id.ToString()) { return true; } return false; } public static bool operator !=(EntityBase entity1, EntityBase entity2) { return (!(entity1 == entity2)); } } }