using System; namespace Kit.Helpers.Extension.Entities { public interface IIdTitle { TId Id { get; set; } TTitle Title { get; set; } } public interface IIdOnly { TId Id { get; set; } } public class IdTitle : IInt32Id, IEquatable, IIdTitle, ICloneable { public IdTitle() { } public IdTitle(int id, string title) : this() { this.Id = id; this.Title = title; } public virtual int Id { get; set; } public virtual string Title { get; set; } #region Empty public static readonly int EmptyId = -1; public static readonly string EmptyTitle = "n/a"; public static TEntity GetEmpty() where TEntity : IdTitle, new() { return new TEntity { Id = EmptyId, Title = EmptyTitle }; } public static IdTitle GetEmpty() { return GetEmpty(); } #endregion /// /// Determines whether the specified is equal to the current . /// /// /// true if the specified is equal to the current ; otherwise, false. /// /// The to compare with the current . 2 public override bool Equals(object obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; if (!(obj is IdTitle)) return false; return Equals((IdTitle)obj); } /// /// Indicates whether the current object is equal to another object of the same type. /// /// /// true if the current object is equal to the parameter; otherwise, false. /// /// An object to compare with this object. public bool Equals(IdTitle other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return other.Id == Id && Equals(other.Title, Title); } /// /// Serves as a hash function for a particular type. /// /// /// A hash code for the current . /// /// 2 public override int GetHashCode() { unchecked { return (Id * 397) ^ (Title != null ? Title.GetHashCode() : 0); } } public object Clone() { return new IdTitle { Id = Id, Title = Title }; } public static bool operator ==(IdTitle left, IdTitle right) { return Equals(left, right); } public static bool operator !=(IdTitle left, IdTitle right) { return !Equals(left, right); } } public class IdTitle : IIdTitle { public IdTitle() { } public IdTitle(TId id, TTitle title) : this() { this.Id = id; this.Title = title; } public IdTitle(IdTitle idTitle) : this() { this.Id = idTitle.Id; this.Title = idTitle.Title; } public virtual TId Id { get; set; } public virtual TTitle Title { get; set; } } public class IdOnly : IIdOnly where TId : struct { public IdOnly() { } public IdOnly(TId id) : this() { this.Id = id; } public IdOnly(IdOnly idTitle) : this() { this.Id = idTitle.Id; } public virtual TId Id { get; set; } } }