public bool Equals(Book other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Title.Equals(other.Title) && Author.Equals(other.Author) && Publisher.Equals(other.Publisher) && Year.Equals(other.Year) && NumOfPages.Equals(other.NumOfPages) && Price.Equals(other.Price)); }
/// <summary> /// Gets a string representation of the <see cref="Book"/> object in <paramref name="format"/> /// using <paramref name="formatProvider"/>. /// </summary> /// <param name="format">A format of string.</param> /// <param name="formatProvider">A format provider.</param> /// <exception cref="FormatException"> /// Thrown when <paramref name="format"/> not found in the enum of string formats. /// </exception> /// <returns>A string representation of the <see cref="Book"/> object in passed format.</returns> public string ToString(string format, IFormatProvider formatProvider) { StringFormat stringFormat; if (!Enum.TryParse <StringFormat>(format.ToUpper(), out stringFormat)) { throw new FormatException("Incorrect string format."); } if (ReferenceEquals(formatProvider, null)) { formatProvider = CultureInfo.CurrentCulture; } switch (stringFormat) { case StringFormat.AT: { return("Author: " + Author + "\nName: " + Name); } case StringFormat.ATH: { return("Author: " + Author + "\nName: " + Name + "\nPublishing house: " + PublishingHouse); } case StringFormat.ATHY: { return("Author: " + Author + "\nName: " + Name + "\nPublishing house: " + PublishingHouse + "\nPublishing year: " + PublishingYear.ToString(formatProvider)); } case StringFormat.IATHYN: { return("ISBN: " + ISBN + "\nAuthor: " + Author + "\nName: " + Name + "\nPublishing house: " + PublishingHouse + "\nPublishing year: " + PublishingYear.ToString(formatProvider) + "\nNumber of pages: " + NumOfPages.ToString(formatProvider)); } case StringFormat.IATHYNP: { return("ISBN: " + ISBN + "\nAuthor: " + Author + "\nName: " + Name + "\nPublishing house: " + PublishingHouse + "\nPublishing year: " + PublishingYear.ToString(formatProvider) + "\nNumber of pages: " + NumOfPages.ToString(formatProvider) + "\nPrice: " + Price.ToString("C", formatProvider)); } default: { throw new FormatException("Incorrect string format."); } } }