54 lines
1.8 KiB
C#
54 lines
1.8 KiB
C#
namespace AyCode.Core.Extensions;
|
|
|
|
public enum AcSerializerType : byte
|
|
{
|
|
Json = 0,
|
|
Binary = 1,
|
|
}
|
|
|
|
public abstract class AcSerializerOptions
|
|
{
|
|
public abstract AcSerializerType SerializerType { get; init; }
|
|
/// <summary>
|
|
/// Whether to use $id/$ref reference handling for circular references.
|
|
/// Default: true
|
|
/// </summary>
|
|
public bool UseReferenceHandling { get; init; } = true;
|
|
|
|
/// <summary>
|
|
/// Maximum depth for serialization/deserialization.
|
|
/// 0 = root level only (primitives of root object)
|
|
/// 1 = root + first level of nested objects/collections
|
|
/// byte.MaxValue (255) = effectively unlimited
|
|
/// Default: byte.MaxValue
|
|
/// </summary>
|
|
public byte MaxDepth { get; init; } = byte.MaxValue;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Options for AcJsonSerializer and AcJsonDeserializer.
|
|
/// </summary>
|
|
public sealed class AcJsonSerializerOptions : AcSerializerOptions
|
|
{
|
|
public override AcSerializerType SerializerType { get; init; } = AcSerializerType.Json;
|
|
|
|
/// <summary>
|
|
/// Default options instance with reference handling enabled and max depth.
|
|
/// </summary>
|
|
public static readonly AcJsonSerializerOptions Default = new();
|
|
|
|
/// <summary>
|
|
/// Options for shallow serialization (root level only, no references).
|
|
/// </summary>
|
|
public static readonly AcJsonSerializerOptions ShallowCopy = new() { MaxDepth = 0, UseReferenceHandling = false };
|
|
|
|
/// <summary>
|
|
/// Creates options with specified max depth.
|
|
/// </summary>
|
|
public static AcJsonSerializerOptions WithMaxDepth(byte maxDepth) => new() { MaxDepth = maxDepth };
|
|
|
|
/// <summary>
|
|
/// Creates options without reference handling.
|
|
/// </summary>
|
|
public static AcJsonSerializerOptions WithoutReferenceHandling() => new() { UseReferenceHandling = false };
|
|
} |