Skip to content

Commit

Permalink
add serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
mjwsteenbergen committed Mar 14, 2024
1 parent 5626f53 commit e248123
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions ApiLibs/NotionRest/Block/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,44 @@ public override NotionBlock ReadJson(JsonReader reader, Type objectType, NotionB
return result;
}

public override bool CanWrite => false;
public override bool CanWrite => true;

public T Seria<T>(JsonWriter writer, JsonSerializer serializer, T value) {
serializer.Serialize(writer, value);
return value;
}

public override void WriteJson(JsonWriter writer, NotionBlock value, JsonSerializer serializer)
{
throw new System.NotImplementedException();
NotionBlock _ = value switch {
Paragraph paragraph => Seria(writer, serializer, paragraph),
Heading3 heading_3 => Seria(writer, serializer, heading_3),
Heading2 heading_2 => Seria(writer, serializer, heading_2),
Heading1 heading_1 => Seria(writer, serializer, heading_1),
BulletedListItem bulleted_list_item => Seria(writer, serializer, bulleted_list_item),
NumberedListItem numbered_list_item => Seria(writer, serializer, numbered_list_item),
ToDo to_do => Seria(writer, serializer, to_do),
Toggle toggle => Seria(writer, serializer, toggle),
ChildPage child_page => Seria(writer, serializer, child_page),
ChildDatabase child_database => Seria(writer, serializer, child_database),
Embed embed => Seria(writer, serializer, embed),
Image image => Seria(writer, serializer, image),
Video video => Seria(writer, serializer, video),
FileBlock file => Seria(writer, serializer, file),
Pdf pdf => Seria(writer, serializer, pdf),
Bookmark bookmark => Seria(writer, serializer, bookmark),
Callout callout => Seria(writer, serializer, callout),
Quote quote => Seria(writer, serializer, quote),
Equation equation => Seria(writer, serializer, equation),
Divider divider => Seria(writer, serializer, divider),
TableOfContents table_of_contents => Seria(writer, serializer, table_of_contents),
Column column => Seria(writer, serializer, column),
ColumnList column_list => Seria(writer, serializer, column_list),
LinkPreview link_preview => Seria(writer, serializer, link_preview),
Code code => Seria(writer, serializer, code),
Unsupported unsupported => Seria(writer, serializer, unsupported),
_ => throw new Exception("Invalid option")
};
}
}
}

0 comments on commit e248123

Please sign in to comment.