public void Serialize(ref JsonWriter writer, Track track, IJsonFormatterResolver formatterResolver) { if (track == null) { writer.WriteNull(); return; } var dateTimeFormatter = formatterResolver.GetFormatter <DateTime>(); UnsafeMemory64.WriteRaw26(ref writer, this.stringByteKeys[0]); dateTimeFormatter.Serialize(ref writer, track.AddedToLibraryDateTime, formatterResolver); UnsafeMemory64.WriteRaw20(ref writer, this.stringByteKeys[1]); formatterResolver.GetFormatter <TrackAlbumAssociation>().Serialize(ref writer, track.AlbumAssociation, formatterResolver); UnsafeMemory64.WriteRaw9(ref writer, this.stringByteKeys[2]); IJsonFormatterHelper.SerializeList(ref writer, track.Composers, formatterResolver); UnsafeMemory64.WriteRaw12(ref writer, this.stringByteKeys[3]); formatterResolver.GetFormatter <TimeSpan?>().Serialize(ref writer, track.Duration, formatterResolver); UnsafeMemory64.WriteRaw17(ref writer, this.stringByteKeys[4]); formatterResolver.GetFormatter <ulong?>().Serialize(ref writer, track.FileSizeBytes, formatterResolver); UnsafeMemory64.WriteRaw11(ref writer, this.stringByteKeys[5]); writer.WriteBoolean(track.IsLoved); UnsafeMemory64.WriteRaw24(ref writer, this.stringByteKeys[6]); formatterResolver.GetFormatter <DateTime?>().Serialize(ref writer, track.LastModifiedDateTime, formatterResolver); UnsafeMemory64.WriteRaw12(ref writer, this.stringByteKeys[8]); formatterResolver.GetFormatter <Uri>().Serialize(ref writer, track.Location, formatterResolver); UnsafeMemory64.WriteRaw14(ref writer, this.stringByteKeys[9]); IJsonFormatterHelper.SerializeList(ref writer, track.Performers, formatterResolver); UnsafeMemory64.WriteRaw9(ref writer, this.stringByteKeys[10]); writer.WriteString(track.Title); UnsafeMemory64.WriteRaw8(ref writer, this.stringByteKeys[11]); formatterResolver.GetFormatter <uint?>().Serialize(ref writer, track.Year, formatterResolver); writer.WriteEndObject(); }
public void Serialize(ref JsonWriter writer, Album album, IJsonFormatterResolver formatterResolver) { if (album == null) { writer.WriteNull(); return; } UnsafeMemory64.WriteRaw11(ref writer, this.stringByteKeys[0]); IJsonFormatterHelper.SerializeList(ref writer, album.Authors, formatterResolver); UnsafeMemory64.WriteRaw14(ref writer, this.stringByteKeys[1]); if (album.DiscsCount.HasValue) { writer.WriteUInt32(album.DiscsCount.Value); } else { writer.WriteNull(); } UnsafeMemory64.WriteRaw9(ref writer, this.stringByteKeys[2]); writer.WriteString(album.Title); // TODO: try use get serialize <uint?> UnsafeMemory64.WriteRaw15(ref writer, this.stringByteKeys[3]); if (album.TracksCount.HasValue) { writer.WriteUInt32(album.TracksCount.Value); } else { writer.WriteNull(); } writer.WriteEndObject(); }
//[MethodImpl(MethodImplOptions.AggressiveInlining)] public static void SerializeList <T>(ref JsonWriter writer, IReadOnlyList <T> list, IJsonFormatterResolver formatterResolver) { IJsonFormatterHelper.SerializeList <T>(ref writer, list, formatterResolver.GetFormatter <T>(), formatterResolver); }