/// <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 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); }