Пример #1
0
 public override string ToString()
 {
     if (String.IsNullOrEmpty(ISBN) || String.IsNullOrEmpty(Author) || String.IsNullOrEmpty(Name) || String.IsNullOrEmpty(Publisher))
     {
         return(base.ToString());
     }
     return(ISBN + Author + Name + Publisher + Year + Pagesquantity.ToString() + Price.ToString());
 }
Пример #2
0
        public string ToString(string format, IFormatProvider provider)
        {
            if (String.IsNullOrEmpty(format))
            {
                format = "G";
            }
            if (provider == null)
            {
                provider = CultureInfo.CurrentCulture;
            }

            switch (format.ToUpperInvariant())
            {
            case "AN":
                return($"AuthorName: {Author}, Title: {Name}");

            case "ANPY":
                return($"AuthorName: {Author}, Title: {Name}, Publisher: {Publisher}, Year: {Year.ToString(provider)}");

            case "IANPYP":
                return($"ISBN 13: {ISBN}, AuthorName: {Author}, Title: {Name}, Publisher: {Publisher}, Year: {Year.ToString(provider)}, Price: {Price.ToString(provider)}");

            case "ANPP":
                return($"AuthorName: {Author}, Title: {Name}, Publisher: {Publisher}, Price: {Price.ToString(provider)}");

            case "G":
                return($"ISBN 13: {ISBN}, AuthorName: {Author}, Title: {Name}, Publisher: {Publisher}, Year: {Year.ToString(provider)}, Number of pages: {Pagesquantity.ToString(provider)}, Price: {Price.ToString(provider)}");

            default:
                throw new FormatException(String.Format("The {0} format string is not supported.", format));
            }
        }