Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 优化注释 #532

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions src/EasilyNET.MongoSerializer.AspNetCore/JsonNodeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,50 @@ namespace EasilyNET.MongoSerializer.AspNetCore;

/// <summary>
/// JsonNode Support
/// <remarks>
/// <para>
/// This serializer handles the serialization and deserialization of <see cref="JsonNode" /> objects.
/// </para>
/// </remarks>
/// </summary>
/// <example>
/// <code>
/// <![CDATA[
/// BsonSerializer.RegisterSerializer(new JsonNodeSerializer());
/// ]]>
/// </code>
/// </example>
public sealed class JsonNodeSerializer : SerializerBase<JsonNode?>
{
private readonly StringSerializer InnerSerializer = new();

/// <summary>
/// if null write {}
/// Serialize to String
/// <remarks>
/// <para>
/// Converts the <see cref="JsonNode" /> object to its string representation for storage.
/// </para>
/// </remarks>
/// </summary>
/// <param name="context"></param>
/// <param name="args"></param>
/// <param name="value"></param>
/// <param name="context">The context in which the serialization is occurring.</param>
/// <param name="args">Additional arguments for the serialization process.</param>
/// <param name="value">The <see cref="JsonNode" /> object to serialize.</param>
public override void Serialize(BsonSerializationContext context, BsonSerializationArgs args, JsonNode? value)
{
InnerSerializer.Serialize(context, args, string.IsNullOrWhiteSpace(value?.ToString()) ? null : value.ToString());
}

/// <summary>
/// if null return {}
/// Deserialize from String
/// <remarks>
/// <para>
/// Converts the stored string representation back into a <see cref="JsonNode" /> object.
/// </para>
/// </remarks>
/// </summary>
/// <param name="context"></param>
/// <param name="args"></param>
/// <returns></returns>
/// <param name="context">The context in which the deserialization is occurring.</param>
/// <param name="args">Additional arguments for the deserialization process.</param>
/// <returns>The deserialized <see cref="JsonNode" /> object.</returns>
public override JsonNode? Deserialize(BsonDeserializationContext context, BsonDeserializationArgs args)
{
var value = InnerSerializer.Deserialize(context, args);
Expand Down