/// <summary> /// IFormattable interface implementation. /// </summary> /// <param name="format">Format type.</param> /// <param name="formatProvider">Culture.</param> /// <returns>Book as a string with particular format.</returns> public string ToString(string format, IFormatProvider formatProvider) { if (string.IsNullOrEmpty(format)) { format = "FULL"; } if (formatProvider == null) { formatProvider = CultureInfo.CurrentCulture; } string outputDateFormat = "yyyy"; switch (format.ToUpperInvariant()) { case "FULL": return ($"ISBN: {ISBN}" + $"\nAuthor: {Author}" + $"\nTitle: {Title}" + $"\nPublisher: {Publisher}" + $"\nYear published: {YearPublished.ToString(outputDateFormat)}" + $"\nPages: {Pages}" + $"\nPrice: {Price}" + $"\n\n"); case "AT": return ($"Author: {Author}" + $"\nTitle: {Title}" + $"\n\n"); case "IATPUYPR": return ($"ISBN: {ISBN}" + $"\nAuthor: {Author}" + $"\nTitle: {Title}" + $"\nPublisher: {Publisher}" + $"\nYear published: {YearPublished.ToString(outputDateFormat)}" + $"\nPrice: {Price}" + $"\n\n"); default: throw new FormatException(string.Format("The {0} format string is not supported.", format)); } }
public override int GetHashCode() { var hashCode = -1891000852; hashCode = hashCode * -1521134295 + Id.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Title); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Author); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Genre); hashCode = hashCode * -1521134295 + YearPublished.GetHashCode(); hashCode = hashCode * -1521134295 + EqualityComparer <string> .Default.GetHashCode(Publisher); hashCode = hashCode * -1521134295 + Rating.GetHashCode(); return(hashCode); }
public override string ToString() { string outputDateFormat = "yyyy"; string bookToString = $"Id: {Id}" + $"\nISBN: {ISBN}" + $"\nAuthor: {Author}" + $"\nTitle: {Title}" + $"\nPublisher: {Publisher}" + $"\nYear published: {YearPublished.ToString(outputDateFormat)}" + $"\nPages: {Pages}" + $"\nPrice: {Price}" + $"\n\n"; return(bookToString); }
public override int GetHashCode() { var hashCode = -619652410; hashCode = (hashCode * -1521134295) + this.Id.GetHashCode(); hashCode = (hashCode * -1521134295) + EqualityComparer <string> .Default.GetHashCode(this.ISBN); hashCode = (hashCode * -1521134295) + EqualityComparer <string> .Default.GetHashCode(Author); hashCode = (hashCode * -1521134295) + EqualityComparer <string> .Default.GetHashCode(Title); hashCode = (hashCode * -1521134295) + EqualityComparer <string> .Default.GetHashCode(Publisher); hashCode = (hashCode * -1521134295) + YearPublished.GetHashCode(); hashCode = (hashCode * -1521134295) + Pages.GetHashCode(); hashCode = (hashCode * -1521134295) + Price.GetHashCode(); return(hashCode); }