public void Serialize(PublishingOffice <T> office, string filename) { using (FileStream stream = new FileStream(filename, FileMode.Create)) { serializer.Serialize(stream, office); } }
public void Serialize(PublishingOffice <T> office, string fileName) { using (StreamWriter writer = new StreamWriter(fileName)) { serializer.Serialize(writer, office); } }
public PublishingOffice <T> Deserialize(string fileName) { using (StreamReader streamReader = new StreamReader(fileName)) using (JsonTextReader jsonTextReader = new JsonTextReader(streamReader)) { PublishingOffice <T> office = serializer.Deserialize <PublishingOffice <T> >(jsonTextReader); return(office); } }
/// <summary> /// Returns representation of book, including <see cref="formatProvider"/> /// <list type="bullet"> /// <item> /// <term>"V"</term> /// <description>Returns representation of book, including Author,Name,Year,PublishingOffice</description> /// </item> /// <item> /// <term>"B"</term> /// <description>Returns representation of book, including Author,Name,Year</description> /// </item> /// <item> /// <term>"S"</term> /// <description>Returns representation of book, including Author,Name</description> /// </item> /// <item> /// <term>"L"</term> /// <description>Returns representation of book, including Name,Year,PublishingOffice</description> /// </item> /// <item> /// <term>"A"</term> /// <description>Returns representation of book, including only Author</description> /// </item> /// <item> /// <term>"N"</term> /// <description>Returns representation of book, including only Name</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 PublishingOffice</description> /// </item> /// <item> /// <term>"I"</term> /// <description>Returns representation of book, including only ISBN</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 "N": return(Name?.ToString(formatProvider) ?? string.Empty); case "Y": return(Year.ToString(formatProvider)); case "H": return(PublishingOffice != null ? "\"" + PublishingOffice?.ToString(formatProvider) + "\"" : string.Empty); case "I": return("ISBN 13: " + ISBN.ToString(formatProvider)); case "P": return("P. " + NumberOfPages.ToString(formatProvider)); case "V": return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider) + ", " + Year.ToString(formatProvider) + ", " + PublishingOffice?.ToString(formatProvider)); case "B": return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider) + ", " + Year.ToString(formatProvider)); case "S": return(Author?.ToString(formatProvider) + ", " + Name?.ToString(formatProvider)); case "L": return(Name?.ToString(formatProvider) + ", " + Year.ToString(formatProvider) + ", " + PublishingOffice?.ToString(formatProvider)); case string str when !str.Except(SimpleFormats).Any(): return(string.Join(", ", format.Select(c => this.ToString(c.ToString(), formatProvider)))); default: throw new FormatException($"The {format} format string is not supported."); } }
/// <inheritdoc /> public override int GetHashCode() { unchecked { var hashCode = ISBN != null?ISBN.GetHashCode() : 0; hashCode = (hashCode * 397) ^ (Author != null ? Author.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (PublishingOffice != null ? PublishingOffice.GetHashCode() : 0); hashCode = (hashCode * 397) ^ Year; hashCode = (hashCode * 397) ^ NumberOfPages; hashCode = (hashCode * 397) ^ Price.GetHashCode(); return(hashCode); } }