Skip to content

Commit 0d612cb

Browse files
author
Cédric Belin
committed
Add the Comment.ToJson() method
1 parent 25c75c2 commit 0d612cb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/comment.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,23 @@ public class Comment(Author author) {
5050
/// The comment's type.
5151
/// </summary>
5252
public string Type { get; set; } = string.Empty;
53+
54+
/// <summary>
55+
/// Returns a JSON representation of this object.
56+
/// </summary>
57+
/// <returns>The JSON representation of this object.</returns>
58+
internal IDictionary<string, string> ToJson() {
59+
var map = Author.ToJson();
60+
if (!string.IsNullOrWhiteSpace(Content)) map["comment_content"] = Content;
61+
// TODO if (Context.Count > 0) map["comment_context"] = Context.ToString();
62+
if (Date is not null) map["comment_date_gmt"] = Date?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")!;
63+
if (Permalink is not null) map["permalink"] = Permalink.ToString();
64+
if (PostModified is not null) map["comment_post_modified_gmt"] = PostModified?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")!;
65+
if (!string.IsNullOrWhiteSpace(RecheckReason)) map["recheck_reason"] = RecheckReason;
66+
if (Referrer is not null) map["referrer"] = Referrer.ToString();
67+
if (!string.IsNullOrWhiteSpace(Type)) map["comment_type"] = Type;
68+
return map;
69+
}
5370
}
5471

5572
/// <summary>

0 commit comments

Comments
 (0)