static void Main(string[] args) { Console.WriteLine("-----------------------"); string input = ""; PublishingHouse house = new PublishingHouse("Sun House", new List <Book>(), 2001, 0); while (true) { Console.WriteLine("To publish book press 1"); Console.WriteLine("To print info press 2"); input = Console.ReadLine(); switch (input) { case "1": Console.WriteLine("How many books you want to publish?"); int amount = Int32.Parse(Console.ReadLine()); List <Book> newBooks = new List <Book>(); for (int i = 0; i < amount; i++) { newBooks.Add(EnterBook()); } house.PublishBooks(newBooks); break; case "2": Console.WriteLine(house.ToString()); break; default: Console.WriteLine("Wrong input"); break; } } }
/// <summary> /// Returns representation of book, including <see cref="formatProvider"/> /// <list type="bullet"> /// <item> /// <term>"V"</term> /// <description>Returns representation of book, including Author,Title,Year,PublishingHouse</description> /// </item> /// <item> /// <term>"B"</term> /// <description>Returns representation of book, including Author,Title,Year</description> /// </item> /// <item> /// <term>"S"</term> /// <description>Returns representation of book, including Author,Title</description> /// </item> /// <item> /// <term>"L"</term> /// <description>Returns representation of book, including Title,Year,PublishingHouse</description> /// </item> /// <item> /// <term>"A"</term> /// <description>Returns representation of book, including only Author</description> /// </item> /// <item> /// <term>"T"</term> /// <description>Returns representation of book, including only Title</description> /// </item> /// <item> /// <term>"Y"</term> /// <description>Returns representation of book, including only Year</description> /// </item> /// <item> /// <term>"H"</term> /// <description>Returns representation of book, including only PublishingHouse</description> /// </item> /// <item> /// <term>"E"</term> /// <description>Returns representation of book, including only Edition</description> /// </item> /// <item> /// <term>"P"</term> /// <description>Returns representation of book, including only Pages</description> /// </item> /// </list> /// </summary> public string ToString(string format, IFormatProvider formatProvider) { if (string.IsNullOrEmpty(format)) { format = "V"; } if (formatProvider == null) { formatProvider = CultureInfo.CurrentCulture; } switch (format.ToUpperInvariant()) { case "A": return(Author?.ToString(formatProvider) ?? string.Empty); case "T": return(Title?.ToString(formatProvider) ?? string.Empty); case "Y": return(Year.ToString(formatProvider)); case "H": return(PublishingHouse?.ToString(formatProvider) ?? string.Empty); case "E": return(Edition.ToString(formatProvider)); case "P": return(Pages.ToString(formatProvider)); case "V": return("Book record: " + Author?.ToString(formatProvider) + ", " + Title?.ToString(formatProvider) + ", " + Year.ToString(formatProvider) + ", " + PublishingHouse?.ToString(formatProvider)); case "B": return("Book record: " + Author?.ToString(formatProvider) + ", " + Title?.ToString(formatProvider) + ", " + Year.ToString(formatProvider)); case "S": return("Book record: " + Author?.ToString(formatProvider) + ", " + Title?.ToString(formatProvider)); case "L": return("Book record: " + Title?.ToString(formatProvider) + ", " + Year.ToString(formatProvider) + ", " + PublishingHouse?.ToString(formatProvider)); case string str when !str.Except(new[] { 'T', 'Y', 'H', 'E', 'P', 'A' }).Any(): return(string.Join(", ", format.Select(c => this.ToString(c.ToString(), formatProvider)))); default: throw new FormatException($"The {format} format string is not supported."); } }